xml get current line number in PHP

In this article I will explain how the xml_get_current_line_number() function can be used in PHP.
  • 2301

xml_get_current_line_number() function in PHP

  • The xml_get_current_line_number() function is used to get the current line number for an XML parser.
  • The xml_get_current_line_number() function returns the current line number on success.
  • The xml_get_current_line_number() function returns FALSE on failure.




  • parser parser is required parameter. it is specify for XML parser to use.

The following example show to how the xml_get_current_line_number() function can be used in PHP.



<h3 style="color: green;">xml_get_current_line_number() function example in PHP</h3>


    $file = "xmltest.xml";

    $xml_parser = xml_parser_create();

    $fp = @fopen($file,'r');

    while ($data = fread($fp,4096))


    if (!xml_parse($xml_parser,$data,feof($fp)))


    die( print "ERROR Name in XML Parser: "

    . xml_error_string(xml_get_error_code($xml_parser))

    . "<br />"

    . "Current Line No. of XML Parser: "

    . xml_get_current_line_number($xml_parser)

    . "<br />"

    . "Current Column No. of XML Parser: "

    . xml_get_current_column_number($xml_parser)

    . "<br />");









You may also want to read these related articles here
Ask Your Question 
Got a programming related question? You may want to post your question here
© 2020 DotNetHeaven. All rights reserved.