plusnplus Posted June 2, 2010 Share Posted June 2, 2010 Hi.. I try to get google weather info into my website. when i try this code: <?php header("content-type: text/xml"); $xmlData = file_get_contents("http://www.google.com/ig/api?weather=new york"); echo $xmlData; ?> i got error : XML Parsing Error: no element found but when i directly type http://www.google.com/ig/api?weather=new york into the browser, it give me the xml file. Any idea how to solve this problem? Thanks for any reply/ help Quote Link to comment https://forums.phpfreaks.com/topic/203596-how-to-solve-xml-parsing-error-no-element-found/ Share on other sites More sharing options...
pornophobic Posted June 2, 2010 Share Posted June 2, 2010 Your browser automatically adds urlencoding for you, when you do it in PHP you need to add it manually, or use urlencode() the solution to your problem would be: <?php header("content-type: text/xml"); $xmlData = file_get_contents("http://www.google.com/ig/api?weather=new%20york"); echo $xmlData; ?> There's always more than one way to do something, though. Quote Link to comment https://forums.phpfreaks.com/topic/203596-how-to-solve-xml-parsing-error-no-element-found/#findComment-1066757 Share on other sites More sharing options...
plusnplus Posted June 3, 2010 Author Share Posted June 3, 2010 Hi pornophobic, it is still give me the same error: XML Parsing Error: no element found it that possible the error because, my company block something in firewall? but like i mention before i able to see without error if i type directly to browser(firefox): http://www.google.com/ig/api?weather=new%20york actually i try other weather api script from yahoo, still not show same error, but not if i put direct in browser. Quote Link to comment https://forums.phpfreaks.com/topic/203596-how-to-solve-xml-parsing-error-no-element-found/#findComment-1066977 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.