note 30179 added to function.str-replace

From: Date: Sun, 09 Mar 2003 20:21:59 +0000
Subject: note 30179 added to function.str-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-45041@lists.php.net to get a copy of this message
Here is yet another modification to the case insensitive stri_replace. With this version, $find can be an array, not unlike str_replace or preg_replace. This is backwards compatable with the previous version of stri_replace. I must admit, I have not compared the performace of this function to preg_replace with the case insensitive flag set for the regular expresion. function stri_replace( $find, $replace, $string ){ if(!is_array($find))$find=array($find); foreach($find as $finding){ $parts = explode( strtolower($finding), strtolower($string) ); $pos = 0; foreach( $parts as $key=>$part ){ $parts[ $key ] = substr($string, $pos, strlen($part)); $pos += strlen($part) + strlen($finding); } $string=join( $replace, $parts ); } return( $string); } -- http://www.php.net/manual/en/function.str-replace.php http://master.php.net/manage/user-notes.php?action=edit+30179 http://master.php.net/manage/user-notes.php?action=delete+30179 http://master.php.net/manage/user-notes.php?action=reject+30179

« previous php.notes (#45041) next »