note 81157 added to function.str-ireplace

From: Date: Fri, 15 Feb 2008 23:28:05 +0000
Subject: note 81157 added to function.str-ireplace
Groups: php.notes 
Request: Send a blank email to php-notes+get-136189@lists.php.net to get a copy of this message
Here are some minor tweaks to-n00b-at-battleofthebits-dot-org's excellent function. 1) The token was set to an ASCII value 1 (which could be changed as was previously noted) 2) The $c++ was not needed 3) The while statement is not necessary for the final replacement 4) Note that this does not allow use of arrays for search and replace terms. That could be implemented using loops. <?php if(!function_exists('str_ireplace')){ function str_ireplace($search,$replace,$subject){ $token = chr(1); $haystack = strtolower($subject); $needle = strtolower($search); while (($pos=strpos($haystack,$needle))!==FALSE){ $subject = substr_replace($subject,$token,$pos,strlen($search)); $haystack = substr_replace($haystack,$token,$pos,strlen($search)); } $subject = str_replace($token,$replace,$subject); return $subject; } } ?> ---- Server IP: 208.69.120.35 Probable Submitter: 76.105.133.145 ---- Manual Page -- http://www.php.net/manual/en/function.str-ireplace.php Edit -- https://master.php.net/note/edit/81157 Del: integrated -- https://master.php.net/note/delete/81157/integrated Del: useless -- https://master.php.net/note/delete/81157/useless Del: bad code -- https://master.php.net/note/delete/81157/bad+code Del: spam -- https://master.php.net/note/delete/81157/spam Del: non-english -- https://master.php.net/note/delete/81157/non-english Del: in docs -- https://master.php.net/note/delete/81157/in+docs Del: other reasons-- https://master.php.net/note/delete/81157 Reject -- https://master.php.net/note/reject/81157 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#136189) next »