我正试图将google api的xml结果保存到文件中,但由于某些原因,即使我想在屏幕上显示它,它也不起作用。有什么想法吗?
<?php
$url ="http://maps.googleapis.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false";
if (file_exists($url)) {
$xml = simplexml_load_file($url);
print_r($xml); # <-- Display in browser
} else {
exit('Failed!');
}
?>
不能将file_exists()
与URL一起使用。如果用file_get_contents()
之类的东西替换它,那么代码的其余部分将按预期工作。