3

I have the following URL : http://localhost:8000/PHPTrialProject/showPlace.php?lat=28.6139391&lng=77.20902120000005

I have extracted the query string from this and stored in two PHP variables :

 $latitude=$_GET['lat'];
 $longitude=$_GET['lng'];
 echo("latitude is : ".$latitude);
 echo("longitude is : ".$longitude);

I then append them to my next URL and try to load it into DOMDocument. I tried two ways :

 $url="http://api.openweathermap.org/data/2.5/weather?lat=".$latitude."&lon=".$longitude;
 $xml3 = $url;
 $xmlDoc3 = new DOMDocument();
 $xmlDoc3->load($xml3);

and

 $xml3 = ("http://api.openweathermap.org/data/2.5/weather?lat=".$latitude."&lon=".$longitude);
 $xmlDoc3 = new DOMDocument();
 $xmlDoc3->load($xml3);

However, both of them give me the following error :

Warning: DOMDocument::load(): Start tag expected, '<' not found in http://api.openweathermap.org/data/2.5/weather?lat=28.6139391&lon=77.20902120000005, line: 1 in C:\xampp\htdocs\PHPTrialProject\showPlace.php on line 98

How do I resolve it?

1 Answer 1

4

The issue is that you're just sending it the URL not the Page itself, use either file_get_contents or cURL and then send it to your DOM document.

E.G

 $xml = file_get_contents("http://api.openweathermap.org/data/2.5/weather?lat=".$latitude."&lon=".$longitude);

 $xmlDoc3 = new DOMDocument();
 $xmlDoc3->load($xml);
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.