I'm trying to use a regex to extract just the longitude and latitude coordinates from this html. This is just a snippet of the full html from http://www.bricodepot.fr/troyes/store/storeDetails.jsp?storeId=1753 so I need to be able to search through the whole targets page html and match the longitude and latitude from this block:
<div class="coordinates">
<i></i>
<strong>Latitude :</strong> 46.369384765625<strong>Longitude :</strong> 2.56929779052734</div>
</div>
This is about as close as I can get at the moment:
preg_match("/<strong>Latitude :<\/strong> (.*?)/", $input_line, $output_array);
which gives:
Array ( [0] => Latitude : [1] => )
Any idea how I can get the cordinates?
You're almost there!
preg_match_all("<strong>L(at|ong)itude :<\/strong>\s([\w\.]*)?", $input_line, $output_array);
And the resulting array will be something like:
Array
(
[0] => Array
(
[0] => <strong>Latitude :</strong> 46.369384765625
[1] => <strong>Longitude :</strong> 2.56929779052734
)
[1] => Array
(
[0] => at
[1] => ong
)
[2] => Array
(
[0] => 46.369384765625
[1] => 2.56929779052734
)
)
preg_match_all("/<strong>Latitude :<\/strong> ([\d\.]+)<strong>Longitude :<\/strong> ([\d\.]+)/", $input_line, $output_array);
The easiest thing you can do is to strip the tags out first. Then your RegExp could be a lot simpler and maintainable.
By stripping the tags, you end up with:
Latitude : 46.369384765625Longitude : 2.56929779052734
Along with this RegExp:
/(?:(Latitude|Longitude) : ([\d\.]+))/
You end up with something like this: http://ideone.com/JGZOZi