• PHP Video Tutorials

PHP - Function XML Parse Into Struct



Syntax

int xml_parse_into_struct ( resource $parser , string $data , array &$values [, array &$index ] )

Definition and Usage

It used to parse any formatted xml into array structure

Return Values

It returns 1 on success or 0 on failure

Parameters

Sr.No Parameters & Description
1

parser

It is used to specifies XML parser to use.

2

xml

It is used to specifies XML data to parse.

3

value_arr

It is used to specifies the target array for the XML data.

4

index_arr

It is used to specifies the target array for index data.

Example

Try out the following example

<?php
   $local = "<para><note>simple note</note></para>";
   $p = xml_parser_create();
   
   xml_parse_into_struct($p, $local, $vals, $index);
   xml_parser_free($p);
   
   echo "Index array is \n";
   print_r($index);
   
   echo "\nVals array\n";
   print_r($vals);
?>

This will produce following result −

Index array Array is ( [PARA] => Array ( [0] => 0 [1] => 2 ) [NOTE] => Array ([0] => 1 ) ) Vals array Array ( 
[0] => Array ( [tag] => PARA [type] => open [level] => 1 ) 
[1] => Array ( [tag] => NOTE [type] => complete [level] => 2 [value] => simple note ) 
[2] => Array ( [tag] => PARA [type] => close [level] => 1 ) )
php_function_reference.htm
Advertisements