note 60099 deleted from function.explode by betz

From: Date: Sat, 11 Feb 2006 16:35:46 +0000
Subject: note 60099 deleted from function.explode by betz
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-103509@lists.php.net to get a copy of this message
Note Submitter: sbc at mail dot bg ---- Hello, this is my first post and the code is not very clean, but it's working and may help someone :-) Thanx to the function of "contact_trieu at hotmail dot com" So, if you have long string, it will hyphenate it into lines with specific length: <? function hyphenate_text($text) { $length = 20; // Length of the rows $hyphenate = "<br>"; // Hyphenate char $startcount = 0; $followcount = 0; $c = 1; for ($i=0; $i<$c; $i++) { $words = explode(' ', $text); $c = count($words); $wcount = 0; $curindex = 0; foreach($words as $value) { if ($followcount > $startcount || $followcount==0) { $wcount += strlen($value)+1; if($wcount>$length-strlen($hyphenate)){ break; } $curindex++; } else{ $followcount++;} } $med_line = implode(' ', array_slice($words, $startcount, $curindex)) . $hyphenate; $startcount += $curindex; $followcount += $startcount; if ($med_line == $hyphenate) {$c=0;} echo $med_line; // Drow Line } } ?>

« previous php.notes (#103509) next »