note 32065 deleted from function.wordwrap by aidan

From: Date: Mon, 19 Jul 2004 23:26:43 +0000
Subject: note 32065 deleted from function.wordwrap by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-73654@lists.php.net to get a copy of this message
Note Submitter: andr3a ---- Try this ... doesn't replace or modify numeric string's parts, if you want and works in a different way of word_wrap function function wrap_selected($text,$size,$tag = " ") { // Usage: wrap_selected("text to modify",word_max_lenght[,"separator tag"]); if(isSet($text)&&isSet($size)) { $ex = explode(" ",$text); $rp = array(); for($i=0; $i<count($ex); $i++) { // delete #&& !is_numeric($ex[$i])# if you want force it anyway 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]; } } return implode(" ",$rp); } return false; } // here an example to view the differences $newtext = "<html> 1234567890123 blablablabla try another word that's not so lenght and look at difference </html>"; $newtext_1 = wrap_selected($newtext,10,"<br />"); print $newtext_1; print "<hr>"; $newtext_2 = wordwrap($newtext,10,"<br />",1); print $newtext_2;

« previous php.notes (#73654) next »