Skip to content

Instantly share code, notes, and snippets.

@johnmorris
Last active October 22, 2015 15:31
Show Gist options
  • Save johnmorris/37f9e96655353c5b70c5 to your computer and use it in GitHub Desktop.
Save johnmorris/37f9e96655353c5b70c5 to your computer and use it in GitHub Desktop.
How to parse XML using SimpleXML and PHP (Tutorial: http://www.johnmorrisonline.com/how-to-parse-xml-with-simplexml-and-php/)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>How to Parse XML With SimpleXML and PHP</title>
</head>
<body>
<?php
$url = 'http://www.johnmorrisonline.com/feed/';
$xml = simplexml_load_file($url) or die("Can't connect to URL");
?><pre><?php print_r($xml); ?></pre><?php
foreach ($xml->channel->item as $item ) {
printf('<li><a href="%s">%s</a></li>', $item->link, $item->title);
}
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment