Dale_G Posted May 15, 2008 Share Posted May 15, 2008 Okay, I'm using Regex to pull the names of certain power tools from an xml style home improvement blog. Basically, this page is made up of <item> <name>Name</name> <description>Description</description> <Format id="xhr_3452" /> </item> Over and over again. Now, I'm trying to get the contents of Format id, which in this case is xhr_3452. $fgc = file_get_contents('http://www.site.org/feed/btg.xml'); preg_match('{id="xhr_([0-9]+)" /}', $fgc , $cms ); echo $cms[1]; And using the code above, I can do that just fine, however theres about 20 other entries on that page in the same format using format id="", but with different content. How can I use regex to get not only the first instance of format id="", but also all OTHERS on the page. So if we see <item> <name>Name</name> <description>Description</description> <Format id="xhr_3452" /> </item> <item> <name>Name</name> <description>Description</description> <Format id="xhr_4564 /> </item> <item> <name>Name</name> <description>Description</description> <Format id="xhr_524" /> </item> <item> <name>Name</name> <description>Description</description> <Format id="xhr_8423" /> </item> I can get ALL the format id's. Also note, the 'xhr_' will not change, so basically all that needs to be retrieved are the numbers. Quote Link to comment Share on other sites More sharing options...
MadTechie Posted May 15, 2008 Share Posted May 15, 2008 try this <?php $fgc = file_get_contents('http://www.site.org/feed/btg.xml'); preg_match_all('/id="xhr_([0-9]+)"/si', $fgc, $cms, PREG_PATTERN_ORDER); $result = $cms[1]; echo "<pre>";print_r($result);echo "</pre>"; ?> Quote Link to comment Share on other sites More sharing options...
Dale_G Posted May 15, 2008 Author Share Posted May 15, 2008 try this <?php $fgc = file_get_contents('http://www.site.org/feed/btg.xml'); preg_match_all('/id="xhr_([0-9]+)"/si', $fgc, $cms, PREG_PATTERN_ORDER); $result = $cms[1]; echo "<pre>";print_r($result);echo "</pre>"; ?> Yeah, exactly what I needed. Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.