cyberkiller Posted May 8, 2007 Share Posted May 8, 2007 I am grabbing a site, I used preg_match to narrow it down to just the snippet I need. The snippet I am using looks like this, <td class="blogPingTime"> 2:26 PM </td> <td> <a href="http://justonemoremile.blogspot.com/" target="_blank"> <img src="/images/feed_icon.png" title="XML feed" alt="XML feed" border="0"> </a> </td> </tr></table> </div> <div id="18" class="blog"> <table class="blog"><tr> <td class="blogName"> <a href="clickthru?url=http://ireland-airfare.laureate-cool-links.info/" class="pingLink"> Ireland Airfare</a> </td> There ten of these, out of each ten I want to grab whats in between class="pingLink"> & </ a> which would be "Ireland Airfare" The text there will be different for each snippet. Here's my expression, preg_match_all("/class=\"pingLink\">(.*?)<\/a>/ims", $info, $parsed); This results with, class="pingLink"> Ireland Airfare</a> How do I get rid of the remaining, class="pingLink"> and </a> ? Link to comment https://forums.phpfreaks.com/topic/50520-html-parsing-almost-have-it-but-stuck/ Share on other sites More sharing options...
effigy Posted May 8, 2007 Share Posted May 8, 2007 That should work. preg_match_all will return the full match and the captured matches. If you want, you can use lookarounds to clean up the full match: /(?<=class=\"pingLink\">)(.*?)(?=<\/a>)/ims. Link to comment https://forums.phpfreaks.com/topic/50520-html-parsing-almost-have-it-but-stuck/#findComment-248198 Share on other sites More sharing options...
cyberkiller Posted May 8, 2007 Author Share Posted May 8, 2007 How would I go about printing out the 10 matches then? preg_match_all("/(?<=class=\"pingLink\">)(.*?)(?=<\/a>)/ims", $info, $parsed); for($i=0 ; $i<=10 ;$i++) { printf ("$parsed[0][$i] <br>"); } Just returns, Array Array Array Link to comment https://forums.phpfreaks.com/topic/50520-html-parsing-almost-have-it-but-stuck/#findComment-248225 Share on other sites More sharing options...
cyberkiller Posted May 8, 2007 Author Share Posted May 8, 2007 haha, nm. Thanks for the help! Link to comment https://forums.phpfreaks.com/topic/50520-html-parsing-almost-have-it-but-stuck/#findComment-248253 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.