PHP& Code Snippets06 Apr 2005 12:05 pm
xml_parser_create xml_parse_into_struct xml_parser_free - very basic XML parser in PHP
Very basic XML parser example using PHP and the ‘–with-xml’ option.
<?php
$parser = xml_parser_create();
xml_parse_into_struct($parser,$xml,&$structure,&$index);
xml_parser_free($parser);
$i = 0;
foreach($structure as $s) {
if($s[”level”] == 2) {
// load results into $res variable
$res[$i] = $s[”value”];
$i++;
}
}
?>
##
The example above gets the level 2 value. You can do a var_dump($structure) to get the entire document/node structure.