• We just launched and are currently in beta. Join us as we build and grow the community.

How to Display XML File using PHP

CyberGh0st12

Social Engineer
C Rep
0
0
0
Rep
0
C Vouches
0
0
0
Vouches
0
Posts
176
Likes
173
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 100 XP
Getting Started

In the previous tutorial, we have discussed on How to create XML file from MySQL Database using PHP. As a continuation, this tutorial will discuss on how to display XML files.

I've used bootstrap to improve the design of 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 our 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.

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Display XML File using PHP</title>
  6. <link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.min.css">
  7. </head>
  8. <body>
  9. <div class="container">
  10. <h1 class="page-header text-center">Display XML File using PHP</h1>
  11. <div class="row">
  12. <div class="col-sm-8 col-sm-offset-2">
  13. <table class="table table-bordered table-striped">
  14. <thead>
  15. <th>UserID</th>
  16. <th>Firstname</th>
  17. <th>Lastname</th>
  18. <th>Address</th>
  19. </thead>
  20. <tbody>
  21. <?php
  22. //load xml file
  23. $file

    =

    simplexml_load_file

    (

    'files/members.xml'

    )

    ;

  24. foreach

    (

    $file

    ->

    user

    as

    $row

    )

    {
  25. ?>
  26. <tr>
  27. <td><?php

    echo

    $row

    ->

    id

    ;

    ?>

    </td>
  28. <td><?php

    echo

    $row

    ->

    firstname

    ;

    ?>

    </td>
  29. <td><?php

    echo

    $row

    ->

    lastname

    ;

    ?>

    </td>
  30. <td><?php

    echo

    $row

    ->

    address

    ;

    ?>

    </td>
  31. </tr>
  32. <?php
  33. }

  34. ?>
  35. </tbody>
  36. </table>
  37. </div>
  38. </div>
  39. </div>

  40. </body>
  41. </html>

That ends this tutorial. Happy Coding :)

 

452,496

338,535

338,543

Top