Sorry Iam feeling a bit of a plank trying to learn php, I think your code will work but how do I get it to take the result of postcode1
and postcode 2 and multiply it by my .55 per mile the script is below thank you for any help you can give me
A total PHP DUMMY
<?php
Sample postcode distance calculator script
July 28th 2004
Define the two postcodes you wish to determine the distance between
$pc1 = "SO41 0RJ";
$pc2 = "SO41 9BZ";
Determine the distance between the two and place the result in $res
$res = calc_distance( $pc1 , $pc2 );
if ($res)
echo "The distance between $pc1 and $pc2 is $res metres";
else
echo "Sorry, one of the postcodes you entered was invalid";
#################################################################################################
Do not edit below here!
#################################################################################################
/**
Determines the distance in metres between two postcodes using a array as an input
@ pca The first postcode
@ pcb The second postcode
@return The distance between the two postcodes in metres
/
function calc_distance( $pca , $pcb ) {
$pca = strtoupper(str_replace(" ","",$pca));
$pcb = strtoupper(str_replace(" ","",$pcb));
// Fetch the data from samknows.com (Do not edit)
$arr = unserialize(file_get_contents("http://www.samknows.com/toys/coords.php?output=php&pc=$pca,$pcb"));
// Check for bad postcode input
if (!$arr[$pca] || !$arr[$pcb]) {
return FALSE;
}
$a = pow(abs($arr[$pca]['Eastings'] - $arr[$pcb]['Eastings']),2);
$b = pow(abs($arr[$pca]['Northings'] - $arr[$pcb]['Northings']),2);
$c = sqrt($a + $b);
return round($c);
}
?>
:π