simplexml error handling php

前端 未结 7 1274
失恋的感觉
失恋的感觉 2020-11-27 19:50

I am using the following code:

function GetTwitterAvatar($username){
$xml = simplexml_load_file(\"http://twitter.com/users/\".$username.\".xml\");
$imgurl =          


        
相关标签:
7条回答
  • 2020-11-27 20:51

    This is an old question, but is still relevant today.

    The correct way to handle exceptions when using the oop SimpleXMLElment is like so.

    libxml_use_internal_errors(TRUE); // this turns off spitting errors on your screen
    try {
      $xml = new SimpleXMLElement($xmlStringOfData);
    } catch (Exception $e) {
      // Do something with the exception, or ignore it.
    }
    
    0 讨论(0)
提交回复
热议问题