English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

PHP xml_parse_into_struct() Function Usage and Example

PHP XML Function Manual

The xml_parse_into_struct() function is used to parse XML data into an array.

Syntax

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

Definition and usage

It is used to parse any formatted XML into an array structure

Return value

Returns successfully1, fails to return 0

Parameter

NumberParameters and descriptions
1

parser

It is used to specify the XML parser to be used.

2

xml

It is used to specify the XML data to be parsed.

3

value_arr

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

4

index_arr

Used to specify the target array for index data.

Online example

Try the following example to parse XML data into an array

<?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  "\nValue index is  \n";
   print_r($vals);
?>
Test and see‹/›

Output result

Index array is  (  [PARA]  =>  Array  (  [0]  =>  0  [1] 2 )  [NOTE]  =>  Array  ([0]  => 1 )  ) 
Value index is  ( 
[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 XML Function Manual