PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Vineet Sethi  >  Simple XML to Array  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: example file
Class: Simple XML to Array
Parse XML documents into arrays
Author: By
Last change:
Date: 13 years ago
Size: 1,485 bytes
 

Contents

Class file image Download
<?php
require_once('xml2array.php');

$xml = '<books><book><title>C programming</title><author rating="3">Balaguruswamy</author></book><book><title>Bookname1</title><author rating="5">Vineet</author></book></books>';
$converter = new Xml2Array();
$converter->setXml($xml);
$xml_array = $converter->get_array();
print_r($xml_array);
/*
 * Array
    (
    [books] => Array
        (
            [book] => Array
                (
                    [0] => Array
                        (
                            [title] => Array
                                (
                                    [#text] => C programming
                                )

                            [author] => Array
                                (
                                    [#text] => Balaguruswamy
                                    [@rating] => 3
                                )

                        )

                    [1] => Array
                        (
                            [title] => Array
                                (
                                    [#text] => Bookname1
                                )

                            [author] => Array
                                (
                                    [#text] => Vineet
                                    [@rating] => 5
                                )

                        )

                )

        )
   
    )
 *
 */
?>

For more information send a message to info at phpclasses dot org.