note 93668 added to function.str-ireplace

From: Date: Tue, 22 Sep 2009 12:29:41 +0000
Subject: note 93668 added to function.str-ireplace
Groups: php.notes 
Request: Send a blank email to php-notes+get-160919@lists.php.net to get a copy of this message
@ mvpetrovich (php4 compatibility with new php5 functions) The count param has been re-added to really be able to transport the code... still not working on arrays but does the job! Also added the check on $needle to avoid strpos exception if invalid char in search is entered (like <) <?php function str_ireplace($search,$replace,$subject,&$count) { $token = chr(1); $haystack = strtolower($subject); $needle = strtolower($search); if (($needle===FALSE) || ($needle=='')) { return $subject; } else { $count = 0; while (($pos=strpos($haystack,$needle))!==FALSE) { $subject = substr_replace($subject,$token,$pos,strlen($search)); $haystack = substr_replace($haystack,$token,$pos,strlen($search)); $count++; } $subject = str_replace($token,$replace,$subject); return $subject; } } ?> ---- Server IP: 208.69.120.35 Probable Submitter: 151.54.226.95 ---- Manual Page -- http://www.php.net/manual/en/function.str-ireplace.php Edit -- https://master.php.net/note/edit/93668 Del: integrated -- https://master.php.net/note/delete/93668/integrated Del: useless -- https://master.php.net/note/delete/93668/useless Del: bad code -- https://master.php.net/note/delete/93668/bad+code Del: spam -- https://master.php.net/note/delete/93668/spam Del: non-english -- https://master.php.net/note/delete/93668/non-english Del: in docs -- https://master.php.net/note/delete/93668/in+docs Del: other reasons-- https://master.php.net/note/delete/93668 Reject -- https://master.php.net/note/reject/93668 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#160919) next »