simplexml error handling php

前端 未结 7 1408
失恋的感觉
失恋的感觉 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:31

    I thinks this is a better way

    $use_errors = libxml_use_internal_errors(true);
    $xml = simplexml_load_file($url);
    if (false === $xml) {
      // throw new Exception("Cannot load xml source.\n");
    }
    libxml_clear_errors();
    libxml_use_internal_errors($use_errors);
    

    more info: http://php.net/manual/en/function.libxml-use-internal-errors.php

提交回复
热议问题