Display XML File Using HTML/PHP PHP Script

Display XML File Using HTML/PHP PHP Script

In this tutorial we will try to read a Simple XML File using PHP script. XML used to create common information formats and data encryption. Some of XML’s advantages are its self-documenting which allows for internationalization in human language that support parsing requirements. By using XML it improved the exponential and simplified capacity of PHP 5. So Let’s see how it do.

Before we started:
First you have to download & install WAMPserver or any local server that run PHP scripts. Here’s the link for WAMP server http://www.wampserver.com/en/.

Creating The XML File
This is where the XML File store all the data that will be later be display via PHP script. Just copy and paste the code below then save it as “phptut.xml”


<?xml version="1.0"?>

<name>Tony Stark</name>
<address>New York</address>

<name>Steeve Roger</name>
<address>New York</address>


<name>Albert Einstein</name>

<name>Nikola Tesla</name>

<name>Thomas Edison</name>

<name>Henry Ford</name>



The PHP Script
This is where the main function happened. The PHP script decrypt the XML file into a readable content to be able to view in the web browser. To do that just simply copy and paste the code below then save it as “index.php”


<!DOCTYPE html>
<html lang = "en">
<meta charset = "UTF-8" name = "viewport" content = "width=device-width, initial-scale=1" />
<link rel = "stylesheet" type = "text/css" href = "css/bootstrap.css"/>
<link rel = "stylesheet" type = "text/css" href = "css/jquery.dataTables.css"/>
<nav class = "navbar navbar-default">
<div class = "container-fluid">
<a class = "navbar-brand" href = "<a href="https://sourcecodester.com">Sourcecodester</a>
" rel="nofollow">https://sourcecodester.com">Sourcecodester</a>
</a> </div>
<div class = "col-md-3"></div>
<div class = "col-md-6 well">
<h3 class = "text-primary">PHP - How To Display XML File Using HTML/PHP</h3>
<hr style = "border-top:1px dotted #000;" />
<table id = "table" class = "table table-bordered" >


$xml = simplexml_load_file('phptut.xml');
foreach($xml->employee as $employee){
echo '

<script src = "js/jquery-3.2.1.js"></script>
<script src = "js/jquery.dataTables.js"></script>

<script type = "text/javascript">


There you have it we’ve able to display a XML file into the web browser using PHP. I hope that this simple tutorial help you understand how a XML file worked with PHP script. For more updates and tutorial just kindly visit this site. Enjoy Coding!!!



Read Me


Have any Question or Comment?

Leave a Reply

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