2011-11-16 79 views
0

我希望能夠檢測誤差的SimpleXMLElement,錯誤是:使用SimpleXMLElement檢測錯誤?

failed to open HTTP stream 
failed to load external entity 
Uncaught exception 'Exception' with message 'String could not be parsed as XML' 

我有以下代碼嘗試檢測錯誤。

$xml = new SimpleXMLElement("https://mail.google.com/mail/feed/atom",null,true); 
if ($xml === FALSE) { 
echo "Wrong username/password combination."; 
} 

這不起作用....我如何使錯誤檢測工作?

回答

1

異常可以使用try抓建設被抓:

try { 
    $oXml 
} 
catch(Excepton $oException) { 
    // Something went wrong! 
} 

對於HTTP /負載問題,我建議你使用的組合:

  1. CURL檢查有效的響應
  2. simplexml_load_string 。解答回覆,並使用libxml_use_internal_errors