Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP中获取在线计算_Php - Fatal编程技术网

在PHP中获取在线计算

在PHP中获取在线计算,php,Php,好的,我使用文件内容从一个网站获取输出,现在我基本上是从这个网站获取结果 范例 我该怎么做?我的意思是这是我目前的代码,但正如你所看到的,它基本上显示了整个网站 function getDistance($x, $y, $xA, $yA) { $distance_ = file_get_contents("http://boulter.com/gps/distance/?from=".$x."+".$y."&to=".$xA."+".$yA."&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_;
    }

如果您想获得距离,下面是一个粗略的示例:

$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°)--"
$distance=文件获取内容(“url”);
//匹配所有td元素,因为数据是表格

preg_match_all('/您希望从该页面中得到什么?距离标题下的值?