note 36785 added to function.substr

From: Date: Wed, 22 Oct 2003 11:20:44 +0000
Subject: note 36785 added to function.substr
Groups: php.notes 
Request: Send a blank email to php-notes+get-59112@lists.php.net to get a copy of this message
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); ?> ---- Manual Page -- http://www.php.net/manual/en/function.substr.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+36785 Delete -- http://master.php.net/manage/user-notes.php?action=delete+36785&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+36785&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#59112) next »