note 30179 deleted from function.str-replace by didou

From: Date: Sat, 16 Aug 2003 09:53:11 +0000
Subject: note 30179 deleted from function.str-replace by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-54318@lists.php.net to get a copy of this message
Note Submitter: php@NOSPAM.stuntlab.com ---- 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); }

« previous php.notes (#54318) next »