note 32067 deleted from function.wordwrap by aidan
| From: | aidan@php.net | Date: | Mon, 19 Jul 2004 23:26:39 +0000 |
| Subject: | note 32067 deleted from function.wordwrap by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-73653@lists.php.net to get a copy of this message | ||
Note Submitter: andr3a
----
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;