note 40592 deleted from function.wordwrap by aidan

From: Date: Mon, 19 Jul 2004 23:25:21 +0000
Subject: note 40592 deleted from function.wordwrap by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-73645@lists.php.net to get a copy of this message
Note Submitter: dawildorcinator@yahoo.no.spam.please.com ---- Here's a kinder more gentle word wrap that i've modified from the previous posts. This one will look for a "Previous" white space before it tries to hack a line in half. function wordwrap3($str,$cols,$cut) { $tag_open = '<'; $tag_close = '>'; $count = 0; $in_tag = 0; $str_len = strlen($str); $segment_width = 0; $last_white_space = 0; $begin_of_line = 0; for ($i=0 ; $i<=$str_len ; $i++){ if ($str[$i] == $tag_open) { $in_tag++; } else { if ($str[$i] == $tag_close) { if ($in_tag > 0) { $in_tag--; } } else { if ($in_tag == 0) { $segment_width++; if ($segment_width > $cols) { if ($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; $begin_of_line = $i; $last_white_space = $i; } else { if ($last_white_space != $begin_of_line) { $i = $last_white_space; } $str = substr($str,0,$i+1).$cut.substr($str,$i+1,$str_len-1); $i += strlen($cut); $str_len = strlen($str); $segment_width = 0; $begin_of_line = $i; $last_white_space = $i; } } else { if ($str[$i] == " ") { $last_white_space = $i; } } } } } } return $str; }

« previous php.notes (#73645) next »