note 91672 added to function.str-ireplace

From: Date: Mon, 22 Jun 2009 14:15:51 +0000
Subject: note 91672 added to function.str-ireplace
Groups: php.notes 
Request: Send a blank email to php-notes+get-157233@lists.php.net to get a copy of this message
My function ext_str_ireplace() from http://www.php.net/manual/de/function.str-ireplace.php#86099 had a few heavy bugs, which I finally found and fixed: <?php // http://devboard.viathinksoft.de/viewtopic.php?f=34&t=771 // Bugfix-Release #3 (June, 22th 2009) function ext_str_ireplace($findme, $replacewith, $subject) { // Replaces $findme in $subject with $replacewith // Ignores the case and do keep the original capitalization by using $1 in $replacewith // Required: PHP 5 $rest = $subject; $result = ''; while (stripos($rest, $findme) !== false) { $pos = stripos($rest, $findme); // Remove the wanted string from $rest and append it to $result $result .= substr($rest, 0, $pos); $rest = substr($rest, $pos, strlen($rest)-$pos); // Remove the wanted string from $rest and place it correctly into $result $result .= str_replace('$1', substr($rest, 0, strlen($findme)), $replacewith); $rest = substr($rest, strlen($findme), strlen($rest)-strlen($findme)); } // After the last match, append the rest $result .= $rest; return $result; } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 141.19.141.25 ---- Manual Page -- http://www.php.net/manual/en/function.str-ireplace.php Edit -- https://master.php.net/note/edit/91672 Del: integrated -- https://master.php.net/note/delete/91672/integrated Del: useless -- https://master.php.net/note/delete/91672/useless Del: bad code -- https://master.php.net/note/delete/91672/bad+code Del: spam -- https://master.php.net/note/delete/91672/spam Del: non-english -- https://master.php.net/note/delete/91672/non-english Del: in docs -- https://master.php.net/note/delete/91672/in+docs Del: other reasons-- https://master.php.net/note/delete/91672 Reject -- https://master.php.net/note/reject/91672 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#157233) next »