So, ive never been very good with regex... Currently im trying to scrape a pages worth of links...
I tried preg_match but its only grabbing the first one, I assume I need to use preg_match_all but its not working as planned...
Here is my code....
I want it to grab the entire link, including the href so I can use it easier.. Currently its outputting like this...
So its pulling out the first one correctly, then its only pulling out the first part of the match which is the "id" for the 2nd link, then its going onto the 3rd and only grabbing the anchor text - its missing like 12 other links on the page...
How the hell can I make it pull the full link code for all of the links on the page?
I tried preg_match but its only grabbing the first one, I assume I need to use preg_match_all but its not working as planned...
Here is my code....
Code:
$regex = '/\<a href\=\"\/reports\/report.cfm\?id\=(.*?)\"\>(.*?)\<\/a\>/';
preg_match_all($regex,$content,$match);
$i=0;
foreach($match as $matches) {
echo "Match $i is $matches[$i]<br />";
$i++;
}
I want it to grab the entire link, including the href so I can use it easier.. Currently its outputting like this...
Code:
Match 0 is <a href="/reports/report.cfm?id=5088">South Beach</a>
<br />
Match 1 is 5087
<br />
Match 2 is Westhaven
<br />
So its pulling out the first one correctly, then its only pulling out the first part of the match which is the "id" for the 2nd link, then its going onto the 3rd and only grabbing the anchor text - its missing like 12 other links on the page...
How the hell can I make it pull the full link code for all of the links on the page?