note 102120 added to function.wordwrap
| From: | altin_bardhi at yahoo dot co dot uk | Date: | Fri, 28 Jan 2011 00:03:55 +0000 |
| Subject: | note 102120 added to function.wordwrap | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-176404@lists.php.net to get a copy of this message | ||
Here I have come out with a possibly very useful wordwrap code snippet.
Apparently what this piece of code does is: it takes the entered text and looks for words longer
than the defined â$chunk_lengthâ if it finds any, it splits the long words and then it
concatenates the whole string back to a new string with longer words separated by a dash character
in this case.
After it has accomplished this task it then inserts an HTML line break after a specified
â$line_lengthâ (Depending on your containers width requirements)
<?php
//Start function explode_ wrap
function explode_wrap($text, $chunk_length, $line_length){
//Explode all the words separated by spaces in a string
$string_chunks = explode(' ', $text);
// Get each split word from the array $sring_chunks_array => key => value
foreach ($string_chunks as $chunk => $value) {
if(strlen($value) >= $chunk_length){
//Split the chunks/words which are longer than $chunk_length
$new_string_chunks[$chunk] = chunk_split($value, $chunk_length, ' - ');
}else {
//Do not split the normal length words
$new_string_chunks[$chunk] = $value;
}
}//End foreach loop
//Concatenate back the all the words
$new_text=implode(' ', $new_string_chunks);
return wordwrap($new_text, $line_length, '<br />');
}//End function
?>
----
Server IP: 69.147.83.197
Probable Submitter: 86.22.161.5
----
Manual Page -- http://www.php.net/manual/en/function.wordwrap.php
Edit -- https://master.php.net/note/edit/102120
Del: integrated -- https://master.php.net/note/delete/102120/integrated
Del: useless -- https://master.php.net/note/delete/102120/useless
Del: bad code -- https://master.php.net/note/delete/102120/bad+code
Del: spam -- https://master.php.net/note/delete/102120/spam
Del: non-english -- https://master.php.net/note/delete/102120/non-english
Del: in docs -- https://master.php.net/note/delete/102120/in+docs
Del: other reasons-- https://master.php.net/note/delete/102120
Reject -- https://master.php.net/note/reject/102120
Search -- https://master.php.net/manage/user-notes.php