How To Display XML File In PHP | CampCodes ...

How to Display XML File in PHP

June 1, 2020
display xml file in php

Getting Started

This tutorial will explain how to display XML files.

I’ve used bootstrap to improve the design of the presentation of this tutorial. This bootstrap is included in the downloadable of this tutorial but, if you want, you may download bootstrap using this link.

Creating a Script

I have included a sample .xml file in the downloadable of this tutorial which I’m going to use to display in the tables of this tutorial.

Create a new file named index.php and paste the codes below.

<!DOCTYPE html>
    <meta charset="utf-8">
    <title>Display XML File using PHP</title>
    <link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.min.css">
<div class="container">
    <h1 class="page-header text-center">Display XML File using PHP</h1>
    <div class="row">
        <div class="col-sm-8 col-sm-offset-2">
            <table class="table table-bordered table-striped">
                    //load xml file
                    $file = simplexml_load_file('files/members.xml');
                    foreach($file->user as $row){
                            <td><?php echo $row->id; ?></td>
                            <td><?php echo $row->firstname; ?></td>
                            <td><?php echo $row->lastname; ?></td>
                            <td><?php echo $row->address; ?></td>

That ends this tutorial. Happy Coding!

Download Code

Leave a Reply

Your email address will not be published. Required fields are marked *