如何使用php从url读取xml文件 [英] how to read xml file from url using php

查看:84
本文介绍了如何使用php从url读取xml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须从URL读取XML文件

I have to read an XML file from an URL

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

这为我提供了一个网址,例如:

This gives me an URL like:

我正在使用此功能读取然后获取数据:

I am using this function to read and then get data:

 $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; 

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

But no luck, any help?

推荐答案

您可以使用"simplexml_load_file"函数从XML中获取数据.请参考此链接

you can get the data from the XML by using "simplexml_load_file" Function. Please refer this link

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从url读取xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆