本文小编将为你奉上10个超级有用的PHP代码片段。
1.查找Longitudes与Latitudes之间的距离
$point2 = array('lat' => 40.758224,'long' => -73.917404);
$distance = getDistanceBetweenPointsNew($point1['lat'],$point1['long'],$point2['lat'],$point2['long']);
foreach ($distance as $unit => $value) {
echo $unit.': '.number_format($value,4).'
';
}
The example returns the following:
miles: 2.6025
feet: 13,741.4350
yards: 4,580.4783
kilometers: 4.1884
meters: 4,188.3894
2.完善cURL功能
<div class="jb51code">
<pre class="brush:php;">
function xcurl($url,$ref=null,$post=array(),$ua="Mozilla/5.0 (X11; Linux x86_64; rv:2.2a1pre) Gecko/20110324 Firefox/4.2a1pre",$print=false) {
$ch = curl_init();
curl_setopt($ch,CURLOPT_AUTOREFERER,true);
if(!empty($ref)) {
curl_setopt($ch,CURLOPT_REFERER,$ref);
}
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
if(!empty($ua)) {
curl_setopt($ch,CURLOPT_USERAGENT,$ua);
}
if(count($post) > 0){
curl_setopt($ch,CURLOPT_POST,CURLOPT_POSTFIELDS,$post);
}
$output = curl_exec($ch);
curl_close($ch);
if($print) {
print($output);
} else {
return $output;
}
}