note 77558 added to function.str-replace
| From: | Stigg at osu1 dot php dot net | Date: | Mon, 03 Sep 2007 22:22:22 +0000 |
| Subject: | note 77558 added to function.str-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-130140@lists.php.net to get a copy of this message | ||
Here's a function which replaces every other occurrence of $victim with $invdr and uses no
regular expressions.
function replace2($string, $victim, $invdr){
$invdr_length = strlen($invdr);
$pos = 0;
$i = 3;
while (!($pos = strpos($string, $victim, $pos)) === FALSE){
if ($i%2) $string = substr_replace($string, $invdr, $pos, $invdr_length);
$i++;
if ($i%2) $pos = $pos + $invdr_length;
}
return $string;
}
----
Server IP: 208.69.120.35
Probable Submitter: 69.141.126.93
----
Manual Page -- http://www.php.net/manual/en/function.str-replace.php
Edit -- https://master.php.net/note/edit/77558
Del: integrated -- https://master.php.net/note/delete/77558/integrated
Del: useless -- https://master.php.net/note/delete/77558/useless
Del: bad code -- https://master.php.net/note/delete/77558/bad+code
Del: spam -- https://master.php.net/note/delete/77558/spam
Del: non-english -- https://master.php.net/note/delete/77558/non-english
Del: in docs -- https://master.php.net/note/delete/77558/in+docs
Del: other reasons-- https://master.php.net/note/delete/77558
Reject -- https://master.php.net/note/reject/77558
Search -- https://master.php.net/manage/user-notes.php