simplexml error handling php

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

    I've found a nice example in the php documentation.

    So the code is:

    libxml_use_internal_errors(true);
    $sxe = simplexml_load_string("");
    if (false === $sxe) {
        echo "Failed loading XML\n";
        foreach(libxml_get_errors() as $error) {
            echo "\t", $error->message;
        }
    }
    

    And the output, as we/I expected:

    Failed loading XML

    Blank needed here
    parsing XML declaration: '?>' expected
    Opening and ending tag mismatch: xml line 1 and broken
    Premature end of data in tag broken line 1
    

提交回复
热议问题