note 79213 deleted from function.str-replace by felipe

From: Date: Sun, 09 Dec 2007 15:46:39 +0000
Subject: note 79213 deleted from function.str-replace by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-133059@lists.php.net to get a copy of this message
Note Submitter: chronic at ghwchronic dot com ---- For those who have a webhost with an earlier version of php that does not support the str_ireplace function but use it, here is one I made today: <?php function str_ireplace($what,$with,$string) { $str_length = strlen($string); $str2_length = strlen($what); for($i=0;$i<$str_length;$i++) { for($j=0;$j<=$str2_length;$j++) { $k = $i + $j; if($j==$str2_length) { $string2 = ""; if($i) $string2 = substr($string,0,$i); $string2 .= $with; if($k!=$str_length) $string2 .= substr($string,$k,$str_length); $string = $string2; $i += strlen($with) - 1; break; } if($k>=$str_length) { break; } $char_string = ord($string[$k]); $char_what = ord($what[$j]); if( !($char_string==$char_what) && !( ($char_string>=97 && $char_string<=122) && ($char_what>=65 && $char_what<=90) && ($char_string-32==$char_what) ) && !( ($char_string>=65 && $char_string<=90) && ($char_what>=97 && $char_what<=122) && ($char_string==$char_what-32) ) ) { break; } } } return $string; } ?>

« previous php.notes (#133059) next »