title: simplexml error handling php
body: <p>I am using the following code:</p>
  
  <pre><code>function GetTwitterAvatar($username){
  $xml = simplexml_load_file("http://twitter.com/users/".$username.".xml");
  $imgurl = $xml-&gt;profile_image_url;
  return $imgurl;
  }
  
  function GetTwitterAPILimit($username, $password){
  $xml = simplexml_load_file("http://$username:$password@twitter.com/account/rate_limit_status.xml");
  $left = $xml-&gt;{"remaining-hits"};
  $total = $xml-&gt;{"hourly-limit"};
  return $left."/".$total;
  }
  </code></pre>
  
  <p>and getting these errors when the stream cannot connect:</p>
  
  <pre><code>Warning: simplexml_load_file(http://twitter.com/users/****.xml) [function.simplexml-load-file]: failed to open stream: HTTP request failed! HTTP/1.0 503 Service Unavailable
  
  Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "http://twitter.com/users/****.xml" 
  
  Warning: simplexml_load_file(http://...@twitter.com/account/rate_limit_status.xml) [function.simplexml-load-file]: failed to open stream: HTTP request failed! HTTP/1.0 503 Service Unavailable
  
  Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "http://***:***@twitter.com/account/rate_limit_status.xml"
  </code></pre>
  
  <p>How can I handle these errors so I can display a user friendly message instead of what is shown above?</p>