note 26912 deleted from function.wordwrap by danbrown
| From: | danbrown@php.net | Date: | Sun, 17 May 2009 18:38:17 +0000 |
| Subject: | note 26912 deleted from function.wordwrap by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155154@lists.php.net to get a copy of this message | ||
Note Submitter: lteague at dashf dot com
----
Yet Another wordwrap replacement-- this one only splits words if the actual word is longer than
$cols, not the line, and it does not break up HTML tags. Perfect for when all you really want to do
is prevent malicious message board posts.
function wordwrap2($str,$cols,$cut) {
$len=strlen($str);
$tag=0;
for ($i=0;$i<$len;$i++) {
$chr = substr($str,$i,1);
if ($chr=="<")
$tag++;
elseif ($chr==">")
$tag--;
elseif (!$tag && $chr==" ")
$wordlen=0;
elseif (!$tag)
$wordlen++;
if (!$tag && !($wordlen%$cols))
$chr .= $cut;
$result .= $chr;
}
return $result;
}