how to read xml file in php
php read xml file |
use below codes to read xml file..
step 1: create user.xml file
<?xml version="1.0" encoding="UTF-8"?> <users> <user> <name>ANJAN KUMAR</name> <about>Web developer</about> <email>Anjankumardhali6@gmail.com</email> </user> <user> <name>Divya Rani</name> <about>Software Engineer</about> <email>divya@gmail.com</email> </user> <user> <name>Anik Roy</name> <about>Web Developer</about> <email>anikroy@gmail.com</email> </user> <user> <name>Prosanto Bain</name> <about>Assistant</about> <email>Prosanto@gmail.com</email> </user> </users>
This is our xml file now we use php to parse this xml file
2. create readxml.php file
readxml to read row from xml file..
<?php //loading xml file $xml = simplexml_load_file("users.xml") or die("Error: Cannot create object"); ?> <table> <tr> <th>Name</th> <th>About</th> <th>Email</th> </tr> <?php foreach ($xml->children() as $row) { ?> <tr> <td><?php echo $row->name;?></td> <td><?php echo $row->about;?></td> <td><?php echo $row->email;?></td> </tr> <?php } ?> </table> <style> table { border-collapse: collapse; width: 50%; font-family:verdana; } th, td { padding: 8px; } tr:nth-child(even){background-color: #f2f2f2} th { background-color: #4CAF50; color: white; } </style>
Your output will look like:
php read xml file |
No comments:
Post a Comment
Thank You for Your Comment
Note: Only a member of this blog may post a comment.