-------------------- -------------------- -------------------- word-wr

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//-------------------------------------------------------------
// word-wrap a string using a zero width space
function soft_wrap($text, $width, $break='​')
{
$wbr = chr(226).chr(128).chr(139);
$words = explode(' ', $text);
foreach($words as $wordnr => $word) {
$word = preg_replace('|([,./\\>?!:;@-]+)(?=.)|', '$1 ', $word);
$parts = explode(' ', $word);
foreach($parts as $partnr => $part) {
$len = strlen(utf8_decode($part));
if (!$len) continue;
$parts[$partnr] = preg_replace('/(.{'.ceil($len/ceil($len/$width)).'})(?=.)/u', '$1'.$wbr, $part);
}
$words[$wordnr] = join($wbr, $parts);
}
return join(' ', $words);
}
//-------------------------------------------------------------
function strip_prefix($str, $pfx) {
return preg_replace('/^'.preg_quote($pfx, '/').'/', '', $str);
}
?>