shocker-z Posted December 24, 2006 Share Posted December 24, 2006 Is there a way that i would be able to parse the information 52.9767 and -1.0986 from the following lines? well from the entire page source?<dl class="geo"> <dt>Lat:</dt> <dd class="latitude">52:58:36N (52.9767)</dd> <dt>Lon:</dt> <dd class="longitude">1:05:55W (-1.0986)</dd></dl>Or no of any ready made scripts?RegardsLiam Link to comment https://forums.phpfreaks.com/topic/31776-parse-long-and-lat-from-multimap/ Share on other sites More sharing options...
fert Posted December 24, 2006 Share Posted December 24, 2006 you could use php's xml functions Link to comment https://forums.phpfreaks.com/topic/31776-parse-long-and-lat-from-multimap/#findComment-147375 Share on other sites More sharing options...
Barand Posted December 25, 2006 Share Posted December 25, 2006 I'd use strpos() to find <dd class="latitude"> then again to find the next occurrence </dd> following that.Use substr() to extract the intervening text.Repeat the process on the extracted text to get the text between "(" and ")".Similarly for the longitude Link to comment https://forums.phpfreaks.com/topic/31776-parse-long-and-lat-from-multimap/#findComment-147429 Share on other sites More sharing options...
shocker-z Posted December 28, 2006 Author Share Posted December 28, 2006 hmm ive just got round to playting wiht it and thought to start with i would create just a litle block of code to size it down faster as </dd> occurs alot before the position i want.The code below starts in the correct position but it echo's right to the bottom of the page??[code]<?php$multimap=file_get_contents('http://www.multimap.com/map/browse.cgi?client=public&search_result=&db=pc&lang=&keepicon=true&pc=NG43QN&advanced=&client=public&addr2=&quicksearch=ng43qn&addr3=&addr1=');$place1=strpos($multimap,'<dt>Lat:</dt>');$place2=strpos($multimap,'<dt>Web Address:</dt>');echo 'long1: '.$place1.'<Br>';echo 'long2: '.$place2.'<Br>';echo substr($multimap, $place1, $place2);?>[/code]can see how it displays @ [url=http://www.ukchat.ws/engineers/untitled2.php]http://www.ukchat.ws/engineers/untitled2.php[/url]RegardsLiam Link to comment https://forums.phpfreaks.com/topic/31776-parse-long-and-lat-from-multimap/#findComment-148697 Share on other sites More sharing options...
Barand Posted December 28, 2006 Share Posted December 28, 2006 tryecho substr($multimap, $place1, $place2-$place1); The 3rd arg is number of characters, not position. Link to comment https://forums.phpfreaks.com/topic/31776-parse-long-and-lat-from-multimap/#findComment-148699 Share on other sites More sharing options...
shocker-z Posted December 28, 2006 Author Share Posted December 28, 2006 wkd mate,working fine, now to get down to business.It's always somthing simple lolLiam Link to comment https://forums.phpfreaks.com/topic/31776-parse-long-and-lat-from-multimap/#findComment-148701 Share on other sites More sharing options...
Barand Posted December 28, 2006 Share Posted December 28, 2006 BTW, the third arg of strpos is the position to search from, so[code]<?php$pos1 = strpos ($multimap, '<dd class="latitude">');$pos2 = strpos ($multimap, '</dd>', $pos1); // srch from pos1echo substr($multimap, $pos1+21, $pos2-($pos1+21)); // allow for length of first string?>[/code]-->52:58:36N (52.9767) Link to comment https://forums.phpfreaks.com/topic/31776-parse-long-and-lat-from-multimap/#findComment-148703 Share on other sites More sharing options...
Barand Posted December 28, 2006 Share Posted December 28, 2006 Oops, see edited code. Didn't allow for the length of the first search string Link to comment https://forums.phpfreaks.com/topic/31776-parse-long-and-lat-from-multimap/#findComment-148705 Share on other sites More sharing options...
shocker-z Posted December 28, 2006 Author Share Posted December 28, 2006 Cheers mate, heres the full code for anyone that needs it :)[code]<form id="form1" name="form1" method="post" action=""> Enter Postcode: <input name="postcode" type="text" id="postcode" /> <input type="submit" name="Submit" value="Submit" /></form><?phpif (isset($_POST['postcode'])) {$multimap=file_get_contents('http://www.multimap.com/map/browse.cgi?client=public&search_result=&db=pc&lang=&keepicon=true&pc='.$_POST['postcode'].'&advanced=&client=public&addr2=&quicksearch=ng43qn&addr3=&addr1=');$place1=strpos($multimap,'<dt>Lat:</dt>');$place2=strpos($multimap,'<dt>Web Address:</dt>');$latlon = substr($multimap, $place1, $place2-$place1);//latitude$lat1 = strpos ($latlon, '<dd class="latitude">');$lat2 = strpos ($latlon, '</dd>', $lat1);$lat = substr($latlon, $lat1+21, $lat2-($lat1+21));$latitude1 = strpos ($lat, '(');$latitude2 = strpos ($lat, ')', $latitude1);$latitude = substr($lat, $latitude1+1, $latitude2-($latitude1+1));//longditude$lon1 = strpos ($latlon, '<dd class="longitude">');$lon2 = strpos ($latlon, '</dd>', $lon1);$lon = substr($latlon, $lon1, $lon2-$lon1);$longitude1 = strpos ($lon, '(');$longitude2 = strpos ($lon, ')', $longitude1);$longitude = substr($lon, $longitude1+1, $longitude2-($longitude1+1));echo 'Lon: '.$longitude.'<Br>';echo 'Lat: '.$latitude.'<Br>';}?>[/code]RegardsLiam Link to comment https://forums.phpfreaks.com/topic/31776-parse-long-and-lat-from-multimap/#findComment-148707 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.