note 32067 added to function.wordwrap

From: Date: Thu, 15 May 2003 09:41:34 +0000
Subject: note 32067 added to function.wordwrap
Groups: php.notes 
Request: Send a blank email to php-notes+get-48013@lists.php.net to get a copy of this message
just the same as above, but with choice true to force numerics and false to leave it numbers function wrap_selected($text,$size,$force,$tag = " ") { // Usage: wrap_selected("text to modify",word_max_lenght,force_numerics[true/false] [,"separator tag"]); if(isSet($text)&&isSet($size)&&is_bool($force)) { $ex = explode(" ",$text); $rp = array(); for($i=0; $i<count($ex); $i++) { if($force==false) { if(strlen($ex[$i])>$size && !is_numeric($ex[$i])) { $where = 0; $rp[$i] = ""; for($b=0; $b<(ceil(strlen($ex[$i])/$size)); $b++) { $rp[$i] .= substr($ex[$i],$where,$size).$tag; $where += $size; } } else { $rp[$i] = $ex[$i]; } } else { if(strlen($ex[$i])>$size) { $where = 0; $rp[$i] = ""; for($b=0; $b<(ceil(strlen($ex[$i])/$size)); $b++) { $rp[$i] .= substr($ex[$i],$where,$size).$tag; $where += $size; } } else { $rp[$i] = $ex[$i]; } } } return implode(" ",$rp); } return false; } // Example $newtext = "<html> 1234567890123 blablablabla try another word that's not so lenght and look at difference </html>"; $newtext_1 = wrap_selected($newtext,10,true,"<br />"); // print modified numerics print $newtext_1."<hr>"; $newtext_2 = wrap_selected($newtext,10,false,"<br />"); // print not modified numerics print $newtext_2; -- http://www.php.net/manual/en/function.wordwrap.php http://master.php.net/manage/user-notes.php?action=edit+32067 http://master.php.net/manage/user-notes.php?action=delete+32067 http://master.php.net/manage/user-notes.php?action=reject+32067

« previous php.notes (#48013) next »