note 76585 added to function.str-ireplace

From: Date: Sat, 21 Jul 2007 06:54:52 +0000
Subject: note 76585 added to function.str-ireplace
Groups: php.notes 
Request: Send a blank email to php-notes+get-128791@lists.php.net to get a copy of this message
Dreamhost hasn't upgraded to PHP 5.0 -- I came up with my own alternative, trying to make it run as much like str_ireplace() as possible. Adjust the switch-a-roo token if you think it may conflict with your needle in teh haystack. ## HOMEBREW str_ireplace() FOR PRE-PHP 5.0 if (!function_exists('str_ireplace') { function str_ireplace($search,$replace,$subject) { $token = '^[[term^]'; $haystack = strtolower($subject); $needle = strtolower($search); while (($pos=strpos($haystack,$needle))!==FALSE) { $c++; $subject = substr_replace($subject,$token,$pos,strlen($search)); $haystack = substr_replace($haystack,$token,$pos,strlen($search)); } while (($pos=strpos($subject,$token))!==FALSE) { $subject = substr_replace($subject,$replace,$pos,strlen($token)); } return $subject; } } ---- Server IP: 208.69.120.35 Probable Submitter: 68.73.56.88 ---- Manual Page -- http://www.php.net/manual/en/function.str-ireplace.php Edit -- https://master.php.net/note/edit/76585 Del: integrated -- https://master.php.net/note/delete/76585/integrated Del: useless -- https://master.php.net/note/delete/76585/useless Del: bad code -- https://master.php.net/note/delete/76585/bad+code Del: spam -- https://master.php.net/note/delete/76585/spam Del: non-english -- https://master.php.net/note/delete/76585/non-english Del: in docs -- https://master.php.net/note/delete/76585/in+docs Del: other reasons-- https://master.php.net/note/delete/76585 Reject -- https://master.php.net/note/reject/76585 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#128791) next »