Friday, June 1, 2012

PHP Simple XML

<?php
// The file test.xml contains an XML document with a root element
// and at least an element /[root]/title.
 

if (file_exists('test.xml')) {
    
$xml simplexml_load_file('test.xml');

    
print_r($xml);
} else {
    exit(
'Failed to open test.xml.');
}

 ?>
This script will display, on success: 
SimpleXMLElement Object
(
  [title] => Example Title
  ...
) 
 
At this point, you can go about using $xml->title
and any other elements.
 
<?php
// Read With Fooreach
foreach($xml as $obj) {
   $obj->element

}
?>
 

No comments:

Post a Comment