note 49546 deleted from function.wordwrap by danbrown

From: Date: Sun, 17 May 2009 18:36:20 +0000
Subject: note 49546 deleted from function.wordwrap by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155145@lists.php.net to get a copy of this message
Note Submitter: radaway ---- I noticed you guys better wordwrap was erasing some characters so I changed it, namely the line: substr($str,0,$i-1).$cut.substr($str,$i,$str_len-1); Hope its of some use. function even_better_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) { //tamos dentro de uma tag html $in_tag++; } elseif ($str[$i] == $tag_close) { //fechamos uma tag html if ($in_tag > 0) $in_tag--; } else { if ($in_tag == 0) { //se nao estamos dentro de uma tag html $segment_width++; if (($segment_width > $cols) && ($str[$i] != " ")) { //se passamos o limite de colunas acrescentamos o $cut no sitio $str = substr($str,0,$i-1).$cut.substr($str,$i,$str_len-1); $i += strlen($cut); $str_len = strlen($str); $segment_width = 0; } } } } return $str; }

« previous php.notes (#155145) next »