2017-01-16 44 views
1

好吧,所以我使用的file_get_contents得到来自网站的输出,现在我基本上是试图从该网站得到的结果在线获取calclulation在PHP

http://boulter.com/gps/distance/?from=44.784129%2C+20.489507&to=44.782793%2C+20.506533&units=k

我该怎么做?我的意思是,这是我当前的代码,但你可以看到它基本上显示整个网站

function getDistance($x, $y, $xA, $yA) { 
     $distance_ = file_get_contents("http://boulter.com/gps/distance/?from=".$x."+".$y."&to=".$xA."+".$yA."&units=k"); 
     echo $distance_; 
    } 
+0

你这是什么想从该页面?距离标题下的值? – Kisaragi

回答

1

如果你想获得的距离,这里有一个粗略的例子,说明:

$distance = file_get_contents('url'); 

//match all td elements since the data is tabular 
preg_match_all('/<td.*(.*?)<\/td>/si', $distance, $matches); 
//remove html tags 
$string = strip_tags($matches[0][0]); 

$distance = substr($string, -26); //ouput is string(26) "1.36 kilometers E (96°)--"