regex - PHP preg_match_all() not capturing subgroups -
i'm trying parse twitter atom feed in php running strange issue. i'm calling preg_match_all
regexp string:
"|<entry>.*<title>(.*)</title>.*<published>(.*)</published>.*</entry>|xsu"
it matches entries ok, captured subgroups title/published not show in results (no arrays captured subgroups created in result object).
now strange part, try capture last bit well:
"|<entry>.*<title>(.*)</title>.*<published>(.*)</published>(.*)</entry>|xsu"
and capturing works. title , published date , large chunk of final data don't want.
i tried add non capturing string "?:" last subgroup capturing stopped working alltogether again.
so how capture data want, without having capture large chunk of unwanted data @ end?
i recommend use dom (or simplexml) parsing rss/atom feeds. way better results regular expressions.
here's example (using simplexml):
$rss_feed = file_get_contents('http://stackoverflow.com/feeds/question/4187945'); $sxml = new simplexmlelement($rss_feed); $title = $sxml->entry[0]->title; echo $title;
Comments
Post a Comment