simplexml_load_file() function error

Reply

Join Date: Jan 2009
Posts: 123
Reputation: shasha821110 is an unknown quantity at this point 
Solved Threads: 2
shasha821110 shasha821110 is offline Offline
Junior Poster

simplexml_load_file() function error

 
0
  #1
Apr 20th, 2009
Hi, all
I am using simplexml_load_file() function to get the rss and change it to the XML and get the elements.
But i got the error information like below:
  1. failed to open stream: HTTP request failed! HTTP/1.0 503 Service Unavailable in

My code is like this:
  1. $zip = 10001;
  2. $url = "http://news.google.com/news?pz=1&ned=us&hl=en&q=".$zip."&output=rss";
  3. $rss = simplexml_load_file($url);

Where is the problem??
Many Thanks.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 189
Reputation: martin5211 is an unknown quantity at this point 
Solved Threads: 14
martin5211 martin5211 is offline Offline
Junior Poster

Re: simplexml_load_file() function error

 
0
  #2
Apr 20th, 2009
Use CURL or fsockopen() to get the result from Google, then simplexml_load_string()

  1. $zip = 10001;
  2. $url = "http://news.google.com/news?pz=1&ned=us&hl=en&q=".$zip."&output=rss";
  3.  
  4. $ch = curl_init();
  5. $timeout = 5; // set to zero for no timeout
  6. curl_setopt($ch, CURLOPT_URL, $url);
  7. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  8. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  9. $result = curl_exec($ch);
  10. curl_close($ch);
  11.  
  12. $rss = simplexml_load_string($result);
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC