note 32065 added to function.wordwrap
| From: | andr3a at rack1 dot php dot net | Date: | Thu, 15 May 2003 08:51:22 +0000 |
| Subject: | note 32065 added to function.wordwrap | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-48011@lists.php.net to get a copy of this message | ||
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;
--
http://www.php.net/manual/en/function.wordwrap.php
http://master.php.net/manage/user-notes.php?action=edit+32065
http://master.php.net/manage/user-notes.php?action=delete+32065
http://master.php.net/manage/user-notes.php?action=reject+32065