Reputation: 1442
I need a regular expression in php to extract the longitude and latitude from this html:
<input type="hidden" value="53.484561000000" id="latitude" />
<input type="hidden" value="-2.951027000000" id="longitude" />
I thought something like this might work:
preg_match('/id="latitude"\s*value="([^"]+)"/', $scrapedHTML, $lat);
preg_match('/id="longitude"\s*value="([^"]+)"/', $scrapedHTML, $lon);
When I do a var_dump of either $lat or $lon I get array(0) {}
Where am I going wrong?
Upvotes: 1
Views: 430
Reputation: 641
You should switch the two parts of your regex. Try:
/value=\"([^"]+)\"\s*id=\"latitude\"/
/value=\"([^"]+)\"\s*id=\"longitude\"/
Upvotes: 2