books.xml : <?xml version="1.0"?> <datas> <books> <book>
<id>1</id> <title>PHP Undercover</title> <author>Arun</author> </book> <book> <id>2</id> <title>PHP Enterprise</title> <author>Vibin</author> </book> </books> </datas>
xmlread.php : <?php
$xml = simplexml_load_file("books.xml") or die("Error: Cannot create object"); //include the books.xml file foreach($xml as $books) // seperate variables, books array from xml file { foreach($books as $book ) // seperate variables, book array from books file { echo $book->id; //display the id echo "<br />"; echo $book->title; //display the title echo "<br />"; echo $book->author; //display the author echo "<br />"; }
} ?>
Output: 1 PHP Undercover Arun 2 PHP Enterprise Vibin
No comments:
Post a Comment