PHP xml_parse_into_struct() Function

In this chapter you will learn:

  1. Description for PHP xml_parse_into_struct() Function
  2. Syntax for PHP xml_parse_into_struct() Function
  3. Parameter for PHP xml_parse_into_struct() Function
  4. Return for PHP xml_parse_into_struct() Function
  5. Example - parses XML data into an array

Description

The xml_parse_into_struct() function parses XML data into an array.

This function parses the XML data into 2 arrays:

  • Value array - containing the data from the parsed XML
  • Index array - containing pointers to the location of the values in the Value array

Syntax

PHP xml_parse_into_struct() Function has the following syntax.

xml_parse_into_struct(parser,xml,value_arr,index_arr)

Parameter

ParameterIs RequiredDescription
parserRequired.XML parser to use
xmlRequired.XML data to parse
value_arrRequired.Target array for the XML data
index_arrOptional.Target array for index data

Return

This function returns 1 on success, or 0 on failure.

Example

XML File


<?xml version="1.0" encoding="ISO-8859-1"?>
<books>//from   j ava2s  .c o  m
  <name>PHP</name>
  <name>Java</name>
</books>

parses XML data into an array


<?php/*from ja  v  a2 s  .c om*/
$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);
?>

Next chapter...

What you will learn in the next chapter:

  1. Description for PHP xml_parser_create() Function
  2. Syntax for PHP xml_parser_create() Function
  3. Parameter for PHP xml_parser_create() Function
  4. Return for PHP xml_parser_create() Function
  5. Example - creates an XML parser