xml get current byte index in PHP

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

xml_get_current_byte_index() function in PHP

  • The xml_get_current_byte_index() function is used to get the byte index for an XML parser.
  • The xml_get_current_byte_index() function returns the current byte index on success.
  • The xml_get_current_byte_index() function returns FALSE on failure.

Syntax

xml_get_current_byte_index(parser)

Parameter

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

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

<html>

<body>

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

    <?php

    $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: "

    . xml_error_string(xml_get_error_code($xml_parser))

    . "<br />"

    . "Line: "

    . xml_get_current_line_number($xml_parser)

    . "<br />"

    . "Column: "

    . xml_get_current_column_number($xml_parser)

    . "<br />"

    . "Byte Index: "

    . xml_get_current_byte_index($xml_parser)

    . "<br />");

    }

    }

    xml_parser_free($xml_parser);

    ?>

</body>

</html>

 

Output

xml-get-current-byte-index-php.gif
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
 
© 2019 DotNetHeaven. All rights reserved.