如何使用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);