PHP xml_parse_into_struct() Function
Complete PHP XML Reference Manual
Definition and Usage
The xml_parse_into_struct() function parses XML data into an array.
This function parses XML data into 2 arrays:
- Value array - Contains the data from the parsed XML
- Index array - Contains pointers to the positions of values in the Value array
On success, this function returns 1. On failure, it returns 0.
Syntax
xml_parse_into_struct(parser,xml,value_arr,index_arr)
| Parameters | Description |
|---|---|
| parser | Required. Specifies the XML parser to use. |
| xml | Required. Specifies the XML data to parse. |
| value_arr | Required. Specifies the target array for the XML data. |
| index_arr | Optional. Specifies the target array for the index data. |
Tips and Notes
**Note:** The xml_parse_into_struct() function returns 1 on success and 0 on failure. This is different from TRUE and FALSE, so be careful when using operators such as ===.
Example
XML file
PHP code
The output of the code above is shown below:
Array
(
[0] => Array
(
[tag] => NOTE
[type] => open
[level] => 1
[value] =>
)
[1] => Array
(
[tag] => TO
[type] => complete
[level] => 2
[value] => Tove
)
[2] => Array
(
[tag] => NOTE
[value] =>
[type] => cdata
[level] => 1
)
[3] => Array
(
[tag] => FROM
[type] => complete
[level] => 2
[value] => Jani
)
[4] => Array
(
[tag] => NOTE
[value] =>
[type] => cdata
[level] => 1
)
[5] => Array
(
[tag] => HEADING
[type] => complete
[level] => 2
[value] => Reminder
)
[6] => Array
(
[tag] => NOTE
[value] =>
[type] => cdata
[level] => 1
)
[7] => Array
(
[tag] => BODY
[type] => complete
[level] => 2
[value] => Don't forget me this weekend!
)
[8] => Array
(
[tag] => NOTE
[value] =>
[type] => cdata
[level] => 1
)
[9] => Array
(
[tag] => NOTE
[type] => close
[level] => 1
)
)
Complete PHP XML Reference Manual