Oh... it's YOU!!! YOU with that camping site... lol. I'm an Eagle scout, love the site. Never been to Texas (as a camper), but love the site.
Anyway, to call the information to your script, use [man]fopen/man, [man]fread/man, [man]file_get_contents/man. Then, just go about finding the info you want.
Something like:
<?php
$rad = 3963.1; // radius of earth in miles
$pi = pi();
$start = 'Baltimore, MD'; // Change these to your $_POST or $_GET var
$end = 'Tampa, FL'; // This too
if(strpos($start, ','))
{
$st = str_replace(',', '%2C', $start);
$st = str_replace(' ', '+', $start);
}
else
{
die(' Format must be in <strong>City</strong>, <em>State Abbreviation</em> format.');
}
if(strpos($end, ','))
{
$en = str_replace(',', '%2C', $end);
$en = str_replace(' ', '+', $end);
}
else
{
die(' Format must be in <strong>City</strong>, <em>State Abbreviation</em> format.');
}
$surl = 'http://zipinfo.com/cgi-local/zipsrch.exe?zip='.$st.'&ll=ll';
$eurl = 'http://zipinfo.com/cgi-local/zipsrch.exe?zip='.$en.'&ll=ll';
// Get the results of our pseudo search
$starting = file_get_contents($surl);
$ending = file_get_contents($eurl);
// We can use a RegEx to get the info we want....
$scode = '<th>Longitude<BR>(West)</th></tr>';
$starting = substr($starting, strpos($starting, $scode), (strpos($starting, '</tr>', strpos($starting, $scode)+35)-strpos($starting, $scode)));
$ending = substr($ending, strpos($ending, $scode), (strpos($ending, '</tr>', strpos($ending, $scode)+35)-strpos($ending, $scode)));
$starting = substr($starting, strpos($starting, '<tr>')+4);
$ending = substr($ending, strpos($ending, '<tr>')+4);
$pat = "@<td align=center>[\d]*</font></td><td align=center>[\w]*</font></td><td align=center>[\w]*</font></td><td align=center>([\d\.]*)</font></td><td align=center>([\d\.]*)</font></td>@";
preg_match($pat, $starting, $scords);
preg_match($pat, $ending, $ecords);
// Get rid of the pesky full match. Not needed, so just shift it off....
array_shift($scords);
array_shift($ecords);
// Get our information into an array
$coords['start']['lat'] = $scords[0];
$coords['start']['lon'] = $scords[1];
$coords['end']['lat'] = $ecords[0];
$coords['end']['lon'] = $ecords[1];
// Convert degrees to radians:
foreach($coords as $k => $arr)
{
foreach($arr as $key => $deg)
{
// We will make 4 variables dynamically here
$s = substr($k, 0, 1).$key;
$$s = ($pi/180)*$deg;
}
}
// The conversion formula to get the distance...
$distance = acos((cos($slat)*cos($slon)*cos($elat)*cos($elon))+(cos($slat)*sin($slon)*cos($elat)*sin($elon))+(sin($slat)*sin($elat)))*$rad;
$miles = round($distance, 4);
echo 'The distance from '.$start.' to '.$end.' is '.$miles.' miles. This is assuming the earth has a radius of '.$rad.' miles.';
?>
Beware: You can't use that more than 15 times (it makes 2 calls to 1 page) per day. Something about bandwith I guess... oh well. But that is an idea. If you can find another page that will give you the degrees, you can follow what I've laid out as a guide and hopefully step yourself through getting it done.
~Brett