Skip to content

Instantly share code, notes, and snippets.

@dipakcg
Created May 11, 2013 12:58
Show Gist options
  • Save dipakcg/5559899 to your computer and use it in GitHub Desktop.
Save dipakcg/5559899 to your computer and use it in GitHub Desktop.
Display XML file contents in webpage using PHP
<?php
$strContent = file_get_contents('YOUR-XML-FILE-PATH.xml'); // eg. http://www.SomeDomain.com/FileName.xml
$arrContent = new SimpleXmlElement($strContent, LIBXML_NOCDATA);
?>
<p> &nbsp; </p>
<div style="margin-left:25px; margin-right: 7px;">
<h2>TITLE GOES HERE</h2>
<div>
<?php
$intI = 0;
foreach($arrContent->item as $key => $objContent)
{
?>
<i>
<p style="margin-top:25px;"><?php
$strContent = $objContent->description;
if(strlen($strContent) > 220)
{
echo substr($strContent,0,220).'...';
}
else
{
echo $strContent;
}
?>
</p>
</i>
<?php
$intI++;
if($intI == 3)
{
break;
}
}
?>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment