note 17396 deleted from function.wordwrap by jimw
| From: | jimw@php.net | Date: | Fri, 14 Dec 2001 20:40:15 +0000 |
| Subject: | note 17396 deleted from function.wordwrap by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-22780@lists.php.net to get a copy of this message | ||
There is a BUG above! When you have sentences shorter than what you intend to cut of -> just the
last word would be shown.
---> This does it...
function mb_wordwrap($str,$width=18) {
//----- default string_length is 18. In small text about 140px width ;)
$elements=preg_split("/[\040\240\254\255]/",$str);
$i=0; $a=0; $out='';
foreach($elements AS $key => $val) {
if((strlen($val)+@strlen(@$row)>$width)) $pos[]=$key; unset($row);
@$row.=$val; $i++;
}
if(is_array(@$pos)) {
foreach($pos AS $key) {
for(;$a<$key;$a++) $out.=' '.$elements[$a];
$out.="\n"; $a=$key;
}
for($b=$key;$b<$i;$b++) $out.=' '.$elements[$b];
} else $out=$str;
return $out;
}