Re: preg help please :)

From: Date: Thu, 16 Oct 2003 06:32:21 +0000
Subject: Re: preg help please :)
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-166274@lists.php.net to get a copy of this message
On Thu, Oct 16, 2003 at 02:23:45PM +1000, Justin French wrote: : : I have the following: : : <? : $quote = "&#822[0|1]{1};"; : $text = preg_replace( : "/$quote(.*)$quote:$quote(.*)$quote/", : "<a href='\\2'>\\1</a>", : $text : ); : ?> : : It basically matches "link text":"url" with the added twist of having : the quotes converted to &#8220; or &#8220; by a previous function. : : It works fine if there is one link found inside a string, but falls : over horribly if there's two links inside a string. : : How can I improve the (.*) to exclude $quote ? Try inverting the greediness with a "U" pattern modifier: "/$quote(.*)$quote:$quote(.*)$quote/U" For more details: http://www.php.net/manual/en/pcre.pattern.modifiers.php

« previous php.general (#166274) next »