2017-01-16 26 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°)--"