note 35244 modified in function.str-replace by aidan

From: Date: Sat, 26 Jun 2004 14:00:37 +0000
Subject: note 35244 modified in function.str-replace by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-71770@lists.php.net to get a copy of this message
Take care with order when using arrays in replacement. <?php $match=array("ONE","TWO","THREE"); $replace=array("TWO WORDS","MANY LETTERS","OTHER IDEAS"); $sample="ONE SAMPLE"; echo str_replace($match,$replace,$sample); ?> It will show: "MANY LETTERS WORDS SAMPLE" That is, after replacing "ONE" with "TWO WORDS", process follows with next array item and it changes "TWO" with "MANY LETTERS". --was-- Take care with order when using arrays in replacement. $match=array("ONE","TWO","THREE"); $replace=array("TWO WORDS","MANY LETTERS","OTHER IDEAS"); $sample="ONE SAMPLE"; echo str_replace($match,$replace,$sample); It will show: "MANY LETTERS WORDS SAMPLE" That is, after replacing "ONE" with "TWO WORDS", process follows with next array item and it changes "TWO" with "MANY LETTERS". http://php.net/manual/en/function.str-replace.php

« previous php.notes (#71770) next »