gpt4 book ai didi

php - 如何使用php从url读取xml文件

转载 作者:IT王子 更新时间:2023-10-29 01:16:14 25 4
gpt4 key购买 nike

我必须从 URL 读取 XML 文件

$map_url = "http://maps.google.com/maps/api/directions/xml?origin=".$merchant_address_url."&destination=".$customer_address_url."&sensor=false";

这给了我一个像这样的 URL:

http://maps.google.com/maps/api/directions/xml?origin=Quentin+Road+Brooklyn%2C+New+York%2C+11234+United+States&destination=550+Madison+Avenue+New+York%2C+New+York%2C+10001+United+States&sensor=false

我正在使用这个函数来读取然后获取数据:

 $response_xml_data = file_get_contents($map_url);
if($response_xml_data){
echo "read";
}

$data = simplexml_load_string($response_xml_data);
echo "<pre>"; print_r($data); exit;

但是没有运气,有什么帮助吗?

最佳答案

您可以使用“simplexml_load_file”函数从 XML 中获取数据。请引用此链接

http://php.net/manual/en/function.simplexml-load-file.php

$url = "http://maps.google.com/maps/api/directions/xml?origin=Quentin+Road+Brooklyn%2C+New+York%2C+11234+United+States&destination=550+Madison+Avenue+New+York%2C+New+York%2C+10001+United+States&sensor=false";
$xml = simplexml_load_file($url);
print_r($xml);

关于php - 如何使用php从url读取xml文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12542469/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com