> Code snippet -> > <?php > > header('Content-type: text/plain'); > > $foo = '<img src="images/php.png"> <img src="images/apache.png">'; > > echo "$foo\n"; > > > $path = '../../../'; > $bar = preg_replace('/(<img src=")(.*">)/', "$1" . $path . "$2", $foo); > > echo $bar;
It's being greedy. Your pattern is matching (<img src=") & (images/php.png"> <img src="images/apache.png">) and inserting $path between the two. Use $bar = preg_replace('/(<img src=")(.*">)/U',"$1" . $path . "$2", $foo); Quote: U (PCRE_UNGREEDY) This modifier inverts the "greediness" of the quantifiers so that they are not greedy by default, but become greedy if followed by "?". It is not compatible with Perl. It can also be set by a (?U) modifier setting within the pattern. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php