Page 1 of 1

Problem using preg_replace

Posted: Mon May 01, 2006 5:33 am
by winsonlee
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Code: Select all

$body1[1] = "<title>afasfasf</title><link>http://www.kafa.com</link><description>afasfasf</description><category>afafasdf</category><pubDate>Sun, 30 Apr 2006 14:08:53 GMT</pubDate></item>";

echo preg_replace('/<title>(.*?)<\/title><link>(.*?)<\/link><description>(.*?)<\/description><category>(.*?)<\/category><pubDate>(.*?)<\/pubDate><\/item>/i', '$5', $body1[1]);

$body1[1] = "
                   <title>aalkdfkasflkasklfasfdlsafasfasf</title>
                   <link>http://www.kafa.com</link>
                   <description>skafdasfasf.</description>
                   <category>kweasfasff</category>
                   <pubDate>Sun, 30 Apr 2006 14:08:53 GMT</pubDate>
               </item>";

echo preg_replace('/<title>(.*?)<\/title><link>(.*?)<\/link><description>(.*?)<\/description><category>(.*?)<\/category><pubDate>(.*?)<\/pubDate><\/item>/i', '$5', $body1[1]);
My first preg_replace works, but somehow the second one doest work.What things did i miss out for the second preg_replace to handle the second string ??


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Mon May 01, 2006 8:02 am
by feyd
add \s* between the tags and add the s modifier after the i modifier.