The xml_parse_into_struct() function parses XML data into an array.
This function parses the XML data into 2 arrays:
PHP xml_parse_into_struct() Function has the following syntax.
xml_parse_into_struct(parser,xml,value_arr,index_arr)
Parameter | Is Required | Description |
---|---|---|
parser | Required. | XML parser to use |
xml | Required. | XML data to parse |
value_arr | Required. | Target array for the XML data |
index_arr | Optional. | Target array for index data |
This function returns 1 on success, or 0 on failure.
XML File
<?xml version="1.0" encoding="ISO-8859-1"?> <books> <name>PHP</name> <name>Java</name> </books>
parses XML data into an array
<?php// w w w . j a va 2 s . c o m
$xmlparser = xml_parser_create();
$fp = fopen('test.xml', 'r');
$xmldata = fread($fp, 1024);
xml_parse_into_struct($xmlparser,$xmldata,$values);
xml_parser_free($xmlparser);
print_r($values);
?>