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> ? Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
cyberkiller Posted May 8, 2007 Author Share Posted May 8, 2007 haha, nm. Thanks for the help! 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.