What does the is_final parameter in xml_parse () do?

I am working on creating a class for parsing xml and have to use this method from PHP called xml_parse

.

It has 3 parameters:

int xml_parse ( resource $parser , string $data [, bool $is_final = false ] )

According to the PHP manual is_final

, this means whether its last piece of data will be sent in this analysis, but what does that mean? is it something to do with resource $parser

? As far as I know, this function does not allow input data stream, thus my confusion.

Someone please explain what he is doing

+3


source to share


1 answer


is_final

means that if you are parsing the last line of yours $data

, you must set this parameter to true.

Also, the Dock has a note:

Entity errors are reported at the end of the parse. And will only show if the "end" parameter is TRUE

      



See sample below from w3schools

<?php
$parser=xml_parser_create();

function char($parser,$data)
  {
  echo $data;
  }

xml_set_character_data_handler($parser,"char");
$fp=fopen("test.xml","r");

while ($data=fread($fp,4096))
  {
  xml_parse($parser,$data,feof($fp)) or 
  die (sprintf("XML Error: %s at line %d", 
  xml_error_string(xml_get_error_code($parser)),
  xml_get_current_line_number($parser)));
  }

xml_parser_free($parser);
?>

      

+2


source







All Articles