PHP XML Tips - Part 2: This post show to us how to read xml from a file. We can use simplexml_load_file() file this:
1 <?php
2 $xml = simplexml_load_file("books.xml")
3 or die("Error: Cannot create object");
4
5 ?>
Before test it, create a file named "books.xml".
01 <?xml version="1.0"?>
02 <datas>
03 <books>
04 <book>
05 <id>1</id>
06 <title>PHP Undercover</title>
07 <author>Wiwit Siswoutomo</author>
08 </book>
09 <book>
10 <id>2</id>
11 <title>PHP Enterprise</title>
12 <author>Wiwit Siswoutomo</author>
13 </book>
14 </books>
15 </datas>
1 <?php
2 $xml = simplexml_load_file("books.xml")
3 or die("Error: Cannot create object");
4
5 ?>
Before test it, create a file named "books.xml".
01 <?xml version="1.0"?>
02 <datas>
03 <books>
04 <book>
05 <id>1</id>
06 <title>PHP Undercover</title>
07 <author>Wiwit Siswoutomo</author>
08 </book>
09 <book>
10 <id>2</id>
11 <title>PHP Enterprise</title>
12 <author>Wiwit Siswoutomo</author>
13 </book>
14 </books>
15 </datas>
No comments:
Post a Comment