PHP Classes
Icontem

File: example


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Ivan Enderlin  >  Clean XML To Array  >  example  
File: example
Role: Example script
Content type: text/plain
Description: how to use this class
Class: Clean XML To Array
Parse a XML document into a nested array
 

Contents

Class file image Download
<?php

header
('Content-type: text/plain');

include(
'lib.xml.php');

$xml = new Xml;


// PARSE


// Parse from a source into a variable (default source type : FILE)
$source '<?xml version="1.0" encoding="utf-8"?>

<test>
  <this a="b">
    <is c="d">
      <a e="f" g="h"> first test</a>
    </is>
    <is>
      <b hello="world">second test</b>
    </is>
  </this>
</test>'
;
$out $xml->parse($sourceNULL);
print_r($out);

/* will output
Array
(
    [this] => Array
        (
            [is] => Array
                (
                    [0] => Array
                        (
                            [a] =>  first test
                            [a-ATTR] => Array
                                (
                                    [e] => f
                                    [g] => h
                                )
                        )
                    [1] => Array
                        (
                            [b] => second test
                            [b-ATTR] => Array
                                (
                                    [hello] => world
                                )
                        )
                )
            [is-ATTR] => Array
                (
                    [c] => d
                )
        )
    [this-ATTR] => Array
        (
            [a] => b
        )
)
*/


// Parse from a local file
$out $xml->parse('myfile.xml''FILE');
print_r($out);

// Parse from a Web file
$out $xml->parse('http://site.tld/myfile.xml''CURL');
print_r($out);



// ENCODING

// You could specify an encoding type (default : utf-8)
$out $xml->parse('myfile.xml''FILE''ISO-8859-15');
print_r($out);

// have fun ;-)

?> 

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products