note 103792 deleted from function.str-replace by danbrown

From: Date: Wed, 04 May 2011 15:46:49 +0000
Subject: note 103792 deleted from function.str-replace by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-179419@lists.php.net to get a copy of this message
Note Submitter: Anonymous ---- Thanks to mevdschee 29-Jan-2011 11:19 for the implementation of the original search_replace. I added the same function to replace str_ireplace and added the optional $count Argument. <?php function str_ireplace_fixed ($search, $replace, $subject, & $count = 0) { $search = array_map('strtolower',$search); $e = '/('.implode('|',array_map('preg_quote', $search)).')/i'; $replace = array_combine($search, $replace); return preg_replace_callback($e, function($v) use ($search, $replace) { return $replace[strtolower($v[1])]; }, $subject, -1, $count); } function str_replace_fixed ($search, $replace, $subject, & $count = 0) { $e = '/('.implode('|',array_map('preg_quote', $search)).')/'; $replace = array_combine($search, $replace); return preg_replace_callback($e, function($v) use ($search, $replace) { return $replace[$v[1]]; }, $subject, -1, $count); }

« previous php.notes (#179419) next »