Get the timestamp for the first day (monday) of a week number

// Offset: numeric weekday of January,
// 1st in given year (e.g. 'Donnerstag' => 4)
$offset = date('w', mktime(0, 0, 0, 1, 1, $weekNumber);
 
// Calculate timestamp of monday from above offset
$offset = ($offset < 5) ? 1-$offset : 8-$offset; $monday = mktime(0, 0, 0, 1 , 1+$offset, $weekNumber);   // Finally: calculate timestamp of monday in requested week return strtotime('+' . ($dateArray[1] - 1) . 'weeks',                  $monday);

Insert a list of values to defined positions of an array (PHP)

if (!is_array($positionArray) || !is_array($originalArray)) {
 
   return $originalArray;
}
 
foreach ($positionArray as $position => $value) {
 
  // position-1 because array_splice position beginns with 0
  $position = $position > 0 ? $position-1 : $position;
 
  array_splice($originalArray, $position,
               $deleteLength, array($value));
}
 
if ($maxLength > 0) {
 
  return array_slice($originalArray, 0, $maxLength);
}
 
return $originalArray;

Shorten a text in consideration of getting full words (PHP)

// Does the text need to be shortened?
if (strlen($text) <= $maxLength) {
  return $text;
}
 
$appendString = '...';
// plus 1, because of prepended space to $appendString
$maxLength = $maxLength - (strlen($appendString)+1);
preg_match("/(.{0,$maxLength}\b)/s", $text, $textShort);
 
$shortenedText = (isset($textShort[0]) ? $textShort[0] : '')
               . ' ' . $appendString;
 
// if the text has not enough words to reach minLenght,
// shorten hard.
if (!isset($textShort[0]) ||
    ($minLength !== null &&
     strlen($textShort[0]) < $minLength)) {
 
// minus 1, because of no prepended space to $appendString
$shortenedText = substr($text, 0, $minLength-1)
               . $appendString;

Regular Expression: find all links and souround them with an A-tag (PHP)

// Convert links with [protocol]://...
$content = preg_replace('/(((f|ht){1}tp(s)?:\/\/)[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)/i',
'<a href="\\1"' . $attributesString . '>\\1</a>', $content);

// Convert links without [protocol]://...
$content = preg_replace('/([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)/i',
'\\1<a href="http://\\2"' . $attributesString . '>\\2</a>', $content);

// Convert mail address
$content = preg_replace('/([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})/i',
'<a href="mailto:\\1"' . $attributesString . '>\\1</a>', $content);