Can you see where my regular expression to match the longitude and lattiude from some scraped html is going wrong?
The script should work by using file_get_contents to load some html then use a regular expression and preg_match to extract the lattitude and longitude. Currently the script below is outputting blank for both latitude and longitude and I'm not sure quite what is wrong and regular expressions are not a very strong area for me. Thanks.
$url = 'http://www.homebase.co.uk/webapp/wcs/stores/servlet/StoreLocatorFlow?slsid=658';
$scrapedPage = file_get_contents($url);
the returned html has a line in it as follows:
<p class="geo"> <abbr class="latitude" title="52.19166">52.19166</abbr> <abbr class="longitude" title="-2.23108">-2.23108</abbr> </p>
We then do preg_match:
preg_match('/class="latitude"\s*title="([^"]+)"/', $scrapedPage, $lat);
preg_match('/class="longitude"\s*title="([^"]+)"/', $scrapedPage, $lon);
echo '<latitude>'.$lat[1].'</latitude>';
echo '<longitude>'.$lon[1].'</longitude>';