Re: greedy preg
| From: | SLanger at spirit21 dot de | Date: | Thu, 07 Aug 2003 07:55:27 +0000 |
| Subject: | Re: greedy preg | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-158617@lists.php.net to get a copy of this message | ||
> preg_replace("|<item>.*?$file.*?</item>|si","",$contents)
> <news>
> <item>
> <title>fhh</title>
> <date>1060205191</date>
> <text>hhh</text>
> <file>xml/news/1060205191.xml</file>
> </item>
> <item>
> <title>fgjghjh</title>
> <date>1060205186</date>
> <text>fgjh</text>
> <file>xml/news/1060205186.xml</file>
> </item>
> <item>
> <title>fgjhh</title>
> <date>1060205182</date>
> <text>fghh</text>
> <file>xml/news/1060205182.xml</file>
> </item>
> </news>
Not sure if I understand you correct but
the way you wrote your replace pattern the result should be
<news></news>.
If you want just the file to be replaced you have to use something like
preg_replace("|<item>.*?($file).*?</item>|si",'\\1',$contents)
Regards
Stefan Langer