note 44055 added to function.str-replace
| From: | kireatgamedesigndotbe at rn2 dot php dot net | Date: | Tue, 13 Jul 2004 19:01:57 +0000 |
| Subject: | note 44055 added to function.str-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-73183@lists.php.net to get a copy of this message | ||
If you want to force a callback (recursion) on the str_replace function, you can combine with
strpos.
<?php
while(strpos($text,$needle) !== false)
{
$text = str_replace($needle,$replace,$text);
}
?>
A clear example:
<?php
$text = ";;;;";
while(strpos($text,";;") !== false)
{
$text = str_replace(";;",";-;",$text);
}
?>
$text will now contain ";-;-;-;"
<?php
$text = ";;;;";
$text = str_replace(";;",";-;",$text);
?>
$text will now contain ";-;;-;"
Don't use stripose instead of strpos, because str_replace is case-sensitive and you'll end
up in an endless loop.
Also, don't just use while(strpos()), your loop will stop immiediately if your occurrence
already is found at position 0!
----
Manual Page -- http://www.php.net/manual/en/function.str-replace.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+44055
Delete -- http://master.php.net/manage/user-notes.php?action=delete+44055&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+44055&report=yes
Search -- http://master.php.net/manage/user-notes.php