xml parse into struct in PHP
In this article I will explain how the xml_parse_into_struct() function can be used in PHP.
xml_parse_into_struct() function in PHP
- The xml_parse_into_struct() function is used to parse XML data into an array.
-
The xml_parse_into_struct() function parses the XML data into 2 arrays.
- Value array - It is containing the data from the parsed XML.
- Index array - It is containing pointers to the location of the values in the Value array.
- The xml_parse_into_struct() function returns 1 on success.
- The xml_parse_into_struct() function returns 0 on failure.
Syntax
xml_parse_into_struct(parser,xml,value_arr,index_arr) |
Parameter
- parser parser is required parameter. it is specify for XML parser to use.
- xml xml is required parameter. It is specify for XML data to parse.
- value_arr value_arr is required parameter. It is specify the target array for the XML data.
- index_arr index_arr is optional parameter. It is specify the target array for the index data.
Example
XML File
<?xml version="1.0" encoding="ISO-8859-1"?>
<message>
<to>User</to>
<from>C-sharpcorner Team</from>
<heading>Wishes</heading>
<body>Have a nice day....!</body>
</message>
|
PHP Code
The following example show to how the xml_parse_into_struct() function can be used in PHP.
<html>
<body>
<h3 style="color: green;">xml_parse_into_struct() function example in PHP</h3>
<?php
$filename = 'parsertest.xml';
$xml_parser = xml_parser_create();
$fp = fopen($filename, 'r');
$data = fread($fp, 4096);
xml_parse_into_struct($xml_parser,$data,$values);
xml_parser_free($xml_parser);
print_r($values);
?>
</body>
</html>
|
Output
You may also want to read these related articles here
Ask Your Question
Got a programming related question? You may want to post your question here