📜  PHP | xml_get_current_line_number()函数

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

PHP | xml_get_current_line_number()函数

xml_get_current_line_number()函数是PHP中的一个内置函数,用于返回 XML 解析器的当前行号。

句法:

int xml_get_current_line_number( resource $xml_parser )

参数:此函数接受一个必需的参数$xml_parser 。它指定要使用的 XML 解析器。
返回值:此函数返回当前正在运行的指定解析器的当前行号,成功时返回 False,失败时返回 False。

笔记:

  • 此函数适用于PHP 4.0.0 及更新版本。
  • 这些示例可能不适用于在线 IDE。因此,尝试在本地服务器或PHP托管服务器上运行它。

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-get-current-line-number。 PHP