📜  PHP | xml_error_string()函数

📅  最后修改于: 2022-05-13 01:56:20.585000             🧑  作者: Mango

PHP | xml_error_string()函数

先决条件: XML 基础
xml_error_string()函数是PHP中的一个内置函数,它为生成的错误代码返回 XML 解析器错误描述。

句法:

string xml_error_string( int $error_code)

参数:此函数接受所需的单个参数$error_code 。它指定从 xml_get_error_code()函数生成的 XML 解析器错误代码。

返回值:此函数返回从 xml_get_error_code() 成功时生成的指定错误代码的 XML 解析器错误描述,失败时返回 False。

注意:此函数适用于PHP 4.0.0 及更新版本。

下面的程序说明了PHP中的 xml_error_string()函数:
gfg.xml 文件:

XML


     user123 
     firstname lastname 
     +91-9876543210 
     I am John Doe. Live in Kolkata, India. 


PHP
Error Code: " .
             
            // Error code
            xml_get_error_code($xml_parser) .
             
            "
Line: " .                           // Line number where the error occurred                xml_get_current_line_number($xml_parser) .                           "
Column: " .                           // Column number where the error occurred                xml_get_current_column_number($xml_parser) .                           "
Byte Index: " .                           // Byte index where the current byte occurred             xml_get_current_byte_index($xml_parser) . "
"         );     } }   // Free to xml parser xml_parser_free($xml_parser);   ?>


XML


     user123 
     firstname lastname 
     +91-9876543210 
     I am John Doe. Live in Kolkata, India. 


PHP
Error Code: " .
             
            // Error code
            xml_get_error_code($xml_parser) .
             
            "
Line: " .                           // Line number where the error occurred                xml_get_current_line_number($xml_parser) .                           "
Column: " .                           // Column number where the error occurred                xml_get_current_column_number($xml_parser) .                           "
Byte Index: " .                           // Byte index where the current byte occurred             xml_get_current_byte_index($xml_parser) . "
"         );     } }   // Free to xml parser xml_parser_free($xml_parser);   ?>


方案一:

PHP

Error Code: " .
             
            // Error code
            xml_get_error_code($xml_parser) .
             
            "
Line: " .                           // Line number where the error occurred                xml_get_current_line_number($xml_parser) .                           "
Column: " .                           // Column number where the error occurred                xml_get_current_column_number($xml_parser) .                           "
Byte Index: " .                           // Byte index where the current byte occurred             xml_get_current_byte_index($xml_parser) . "
"         );     } }   // Free to xml parser xml_parser_free($xml_parser);   ?>

输出:

ERROR: Mismatched tag
Error Code: 76
Line: 7
Column: 13
Byte Index: 208

极客.xml 文件:

XML



     user123 
     firstname lastname 
     +91-9876543210 
     I am John Doe. Live in Kolkata, India. 

方案二:

PHP

Error Code: " .
             
            // Error code
            xml_get_error_code($xml_parser) .
             
            "
Line: " .                           // Line number where the error occurred                xml_get_current_line_number($xml_parser) .                           "
Column: " .                           // Column number where the error occurred                xml_get_current_column_number($xml_parser) .                           "
Byte Index: " .                           // Byte index where the current byte occurred             xml_get_current_byte_index($xml_parser) . "
"         );     } }   // Free to xml parser xml_parser_free($xml_parser);   ?>

输出:

ERROR: String not closed expecting " or '
Error Code: 34
Line: 1
Column: 36
Byte Index: 37

参考: https://www. PHP.net/manual/en/函数.xml 错误字符串。 PHP