note 25593 added to function.wordwrap
| From: | info-at-oxyscripts-dot-com at rack1 dot php dot net | Date: | Sun, 29 Sep 2002 20:59:18 +0000 |
| Subject: | note 25593 added to function.wordwrap | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-37397@lists.php.net to get a copy of this message | ||
Jeffrey Sambells code above has a few errors in it that prevented it working properly, which I have
changed so that it works as desired. It will wrap a string properly, and exclude HTML from wrapping.
function even_better_wordwrap($str,$cols,$cut) {
$tag_open = '<';
$tag_close = '>';
$count = 0;
$in_tag = 0;
$str_len = strlen($str);
$segment_width = 0;
for ($i=0 ; $i<=$str_len ; $i++){
if ($str[$i] == $tag_open) {
$in_tag++;
} elseif ($str[$i] == $tag_close) {
if ($in_tag > 0) {
$in_tag--;
}
} else {
if ($in_tag == 0) {
$segment_width++;
if (($segment_width > $cols) && ($str[$i] != " ")) {
$str = substr($str,0,$i).$cut.substr($str,$i+1,$str_len-1);
$i += strlen($cut);
$str_len = strlen($str);
$segment_width = 0;
}
}
}
}
return $str;
}
Alex
http://www.oxyscripts.com
--
http://www.php.net/manual/en/function.wordwrap.php
http://master.php.net/manage/user-notes.php?action=edit+25593
http://master.php.net/manage/user-notes.php?action=delete+25593
http://master.php.net/manage/user-notes.php?action=reject+25593