我有一段用于距离计算器的简单代码,我在这里找到了它。
但是,我不知道为什么当我将它上传到我的服务器时它根本不起作用!
这是代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<body>
<?php
$distances = array();
$distances[0] = array("id"=>"0","name"=>"Pittsburgh","long"=>"-79.9954","lat"=>"40.4409");
$distances[1] = array("id"=>"1","name"=>"Las Vegas","long"=>"-94.1024","lat"=>"36.1749");
$distances[2] = array("id"=>"2","name"=>"Beaumont","long"=>"-79.9954","lat"=>"30.0862");
$distances[3] = array("id"=>"3","name"=>"South Bend","long"=>"-86.2517","lat"=>"41.673");
$distances[4] = array("id"=>"4","name"=>"Hampton","long"=>"-76.3447","lat"=>"37.03");
$distances[5] = array("id"=>"5","name"=>"Savannah","long"=>"-81.0946","lat"=>"32.0728");
if(getenv("REQUEST_METHOD")=="POST")
{
$lon1 = $distances[$from]["long"];
$lat1 = $distances[$from]["lat"];
$lon2 = $distances[$to]["long"];
$lat2 = $distances[$to]["lat"];
$distance = (3958*3.1415926*sqrt(($lat2-$lat1)*($lat2-$lat1) + cos($lat2/57.29578)*cos($lat1/57.29578)*($lon2-$lon1)*($lon2-$lon1))/180);
$summary = "Total distance between ".$distances[$from]["name"]." and ".$distances[$to]["name"]." is ".sprintf("%01.02d",$distance)." km";
$summary.= "<br><br>( $lon1,$lat1 ) ($lon2,$lat2)";
}
?>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><form name="form1" method="post" action="">
<table width="400" border="0" cellpadding="0" cellspacing="0" class="bodytext">
<tr>
<td width="166"><select name="from" class="bodytext">
<?php foreach ($distances as $value){?>
<option <?php if($from==$value["id"])print("selected");?> value="<?php print($value["id"]);?>"><?php print($value["name"]);?></option>
<?php }?>
</select></td>
<td width="117"><select name="to" class="bodytext">
<?php foreach ($distances as $value){?>
<option <?php if($to==$value["id"])print("selected");?> value="<?php print($value["id"]);?>"><?php print($value["name"]);?></option>
<?php }?>
</select></td>
<td width="117"><input name="Submit" type="submit" class="bodytext" value="Calculate"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="3">
<?php print($summary); ?></td>
</tr>
</table>
</form></td>
</tr>
</table>
</body></html>
我错过了什么吗?我现在已经更新了代码。最后一个代码是错误的。对于那个很抱歉。