note 44055 deleted from function.str-replace by tomsommer

From: Date: Tue, 13 Jul 2004 19:47:05 +0000
Subject: note 44055 deleted from function.str-replace by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-73184@lists.php.net to get a copy of this message
Note Submitter: kire at gamedesign dot be ---- 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!

« previous php.notes (#73184) next »