我有以下URL:http:// localhost:8000 / PHPTrialProject / showPlace.php?lat = 28.6139391&lng = 77.20902120000005
我从中提取了查询字符串,并将其存储在两个PHP变量中:
$latitude=$_GET['lat'];
$longitude=$_GET['lng'];
echo("latitude is : ".$latitude);
echo("longitude is : ".$longitude);
然后,我将它们附加到下一个URL,然后尝试将其加载到DOMDocument中。我尝试了两种方法:
$url="http://api.openweathermap.org/data/2.5/weather?lat=".$latitude."&lon=".$longitude;
$xml3 = $url;
$xmlDoc3 = new DOMDocument();
$xmlDoc3->load($xml3);
和
$xml3 = ("http://api.openweathermap.org/data/2.5/weather?lat=".$latitude."&lon=".$longitude);
$xmlDoc3 = new DOMDocument();
$xmlDoc3->load($xml3);
但是,他们两个都给我以下错误:
警告:DOMDocument :: load():预期的开始标签,在http://api.openweathermap.org/data/2.5/weather?lat=28.6139391&lon=77.20902120000005中未找到“ <” ,行:C:\ xampp中的1第98行的\ htdocs \ PHPTrialProject \ showPlace.php
我该如何解决?
问题是您只是向其发送URL,而不是页面本身,使用file_get_contents或cURL,然后将其发送到DOM文档。
例如
$xml = file_get_contents("http://api.openweathermap.org/data/2.5/weather?lat=".$latitude."&lon=".$longitude);
$xmlDoc3 = new DOMDocument();
$xmlDoc3->load($xml);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句