note 17279 added to function.wordwrap
| From: | na8ur at na8ur dot com | Date: | Mon, 03 Dec 2001 09:48:33 +0000 |
| Subject: | note 17279 added to function.wordwrap | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-21552@lists.php.net to get a copy of this message | ||
I tried some of the functions above to have a workaround for wordwrap on php 4.01 somehow they all
didn`t do what I thought a wordwrap for "germans" ;) should do.
Maybe this solution isn`t the fastest but ... working properly.
//-----
function mb_wordwrap($str,$width=140) {
$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++;
}
foreach($pos AS $key) {
for(;$a<$key;$a++) {
$out.=' '.$elements[$a];
}
$out.="\n";
$a=$key;
}
for($b=$key;$b<$i;$b++) {
$out.=' '.$elements[$b];
}
return $out;
}
--
http://www.php.net/manual/en/function.wordwrap.php
http://master.php.net/manage/user-notes.php?action=edit+17279
http://master.php.net/manage/user-notes.php?action=delete+17279
http://master.php.net/manage/user-notes.php?action=reject+17279