note 17396 added to function.wordwrap

From: Date: Thu, 06 Dec 2001 21:43:01 +0000
Subject: note 17396 added to function.wordwrap
Groups: php.notes 
Request: Send a blank email to php-notes+get-21723@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; } -- http://www.php.net/manual/en/function.wordwrap.php http://master.php.net/manage/user-notes.php?action=edit+17396 http://master.php.net/manage/user-notes.php?action=delete+17396 http://master.php.net/manage/user-notes.php?action=reject+17396

« previous php.notes (#21723) next »