note 36785 deleted from function.substr by vincent
| From: | vincent@php.net | Date: | Wed, 22 Oct 2003 12:01:55 +0000 |
| Subject: | note 36785 deleted from function.substr by vincent | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-59116@lists.php.net to get a copy of this message | ||
Note Submitter: xeen DOT(lol) dc AT(lol) web DOT(lol) de
----
If you want my function to ignore ueh... if the text is written small or BIG (I know this is wrong
but you unterstand me) you got to replace (4th line)...
$text = split("$break",$text);
...with this...
$text=preg_replace("/$break/i",strtolower($break),$text);
$text = split(strtolower("$break"),$text);
So again, heres the complete function again, see the examples above.
<?
function limitchars($text,$lim,$break,$tail)
{
$text=preg_replace("/$break/i",strtolower($break),$text);
$text = split(strtolower("$break"),$text);
if(strlen(implode("$break",$text))>=$lim)
{
$i=0;
$add_str="";
while($i<=count($text))
{
$add_str=$text[$i];
$out[]=$add_str;
if(strlen(implode("$break",$out))>$lim-strlen($break)) { break; }
$add_str="";
$i++;
}
$text=implode("$break",$out);
if(substr($text,0,-strlen($break))==$break) $text=substr($text,0,-strlen($break));
$text="$text$tail";
}
else
{
$text=implode("$break",$text);
}
return $text;
}
echo limitchars($data,$linebreak,$splitter,$tail);
?>