note 75177 added to function.wordwrap
| From: | phpsales at gmail dot com | Date: | Wed, 16 May 2007 16:53:08 +0000 |
| Subject: | note 75177 added to function.wordwrap | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-126645@lists.php.net to get a copy of this message | ||
########################################
# Break long words with out cutting HTML tags.
########################################
/* Break Long Words (string, int, char) */
function breakLongWords($str, $maxLength, $char){
$wordEndChars = array(" ", "\n", "\r", "\f",
"\v", "\0");
$count = 0;
$newStr = "";
$openTag = false;
for($i=0; $i<strlen($str); $i++){
$newStr .= $str{$i};
if($str{$i} == "<"){
$openTag = true;
continue;
}
if(($openTag) && ($str{$i} == ">")){
$openTag = false;
continue;
}
if(!$openTag){
if(!in_array($str{$i}, $wordEndChars)){//If not word ending char
$count++;
if($count==$maxLength){//if current word max length is reached
$newStr .= $char;//insert word break char
$count = 0;
}
}else{//Else char is word ending, reset word char count
$count = 0;
}
}
}//End for
return $newStr;
}
----
Server IP: 69.147.83.197
Probable Submitter: 75.176.134.57
----
Manual Page -- http://www.php.net/manual/en/function.wordwrap.php
Edit -- https://master.php.net/note/edit/75177
Del: integrated -- https://master.php.net/note/delete/75177/integrated
Del: useless -- https://master.php.net/note/delete/75177/useless
Del: bad code -- https://master.php.net/note/delete/75177/bad+code
Del: spam -- https://master.php.net/note/delete/75177/spam
Del: non-english -- https://master.php.net/note/delete/75177/non-english
Del: in docs -- https://master.php.net/note/delete/75177/in+docs
Del: other reasons-- https://master.php.net/note/delete/75177
Reject -- https://master.php.net/note/reject/75177
Search -- https://master.php.net/manage/user-notes.php