note 60099 added to function.explode

From: Date: Mon, 26 Dec 2005 20:18:00 +0000
Subject: note 60099 added to function.explode
Groups: php.notes 
Request: Send a blank email to php-notes+get-100750@lists.php.net to get a copy of this message
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 } } ?> ---- Manual Page -- http://www.php.net/manual/en/function.explode.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+60099 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60099&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60099&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60099&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60099&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60099&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60099&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60099&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+60099&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#100750) next »