Hi there captainbarner,
I would suggest tha you use
simplexml_load_file rather than
simplexml_load_string
Using a sample xml file from
https://www.learningcontainer.com/sample-xml-file/,
here is a basic example...
PHP Code:
<?php
$xmldata = simplexml_load_file(
"https://www.learningcontainer.com/wp-content/uploads/2020/03/Sample-employee-XML-file.xml")
or die("Failed to load");
?>
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,height=device-height,initial-scale=1">
<title>using xml data</title>
<link rel="stylesheet" href="screen.css" media="screen">
<style media="screen">
body {
background-color: #f9f9f9;
font: normal 1em / 1.5em sans-serif;
}
h1{
font-size: 1.5em;
color: #444;
text-align: center;
}
table {
margin: auto;
border-collapse: collapse;
background-color: #fff;
}
th,td {
padding: 0.25em 0.5em;
border: 1px solid #000;
}
</style>
</head>
<body>
<h1>PHP display XML content</h1>
<table>
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Title</th>
<th>Division</th>
<th>Building</th>
<th>Room</th>
</tr>
</thead>
<tbody>
<?php
foreach($xmldata->children() as $empl) {
echo "<tr>\n";
echo "<td>". $empl->firstname . "</td>\n";
echo "<td>". $empl->lastname . "</td>\n";
echo "<td>". $empl->title . "</td>\n";
echo "<td>". $empl->division . "</td>\n";
echo "<td>". $empl->building . "</td>\n";
echo "<td>". $empl->room . "</td></tr>\n";
}
?>
</tbody>
</table>
</body>
</html>
Note
You will need to upload this code as a PHP file to your site for it to work or use a local server such as
XAMPP
coothead
Bookmarks