Re: Search a string between <foo></foo>

From: Date: Wed, 09 May 2001 12:06:24 +0000
Subject: Re: Search a string between <foo></foo>
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-52092@lists.php.net to get a copy of this message
.* in your patten will match everything It's greedy like perl (unless you compiled php not to be) add a ? and it will make it none greedy ^[<foo>]* will not work ^ needs to be in [] to mean not else it means start of string ""Luiz Vitor"" <lvdamin@terra.com.br> wrote in message news:011201c0d87d$57f8ab00$4600a8c0@vilagenet.com.br... Hi... I have a text and, some words of the text have the tags <url></url> between them. What i'm trying to do is to replace the word between that tags for a url, wich I'll search them in a database and convert to a url. It's working fine when I have only one <url></url>, but when there are more than one, the script converts all the text between the first <foo></foo> and the last <foo></foo>. I'm using this code: if (eregi("<foo>(.*)</foo>", $string, $result)) { $string = str_replace($result[1], '<a href="'.$result[1].'">'.$result[1].'</a>', $string); } Someone knows what I have to do to put it to work??? Thanks in advance. Luiz Vitor Brazil

« previous php.general (#52092) next »