note 26912 added to function.wordwrap
| From: | lteague at dashf dot com | Date: | Sun, 17 Nov 2002 16:50:37 +0000 |
| Subject: | note 26912 added to function.wordwrap | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-39595@lists.php.net to get a copy of this message | ||
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;
}
--
http://www.php.net/manual/en/function.wordwrap.php
http://master.php.net/manage/user-notes.php?action=edit+26912
http://master.php.net/manage/user-notes.php?action=delete+26912
http://master.php.net/manage/user-notes.php?action=reject+26912