/** * Purpose: create SimpleXML object from a file or from scratch * @param string $path - file path to an xml file * @param string $rootName - the name of the root element in the xml file */ public function __construct($path = null, $rootName = "root") { if (!empty($path)) { $this->xmlFilePath = $path; //if the file path is to an existing file -load the file if (file_exists($path)) { $this->rootNode = simplexml_load_file($path); } else { //if the file does not exist create a SimpleXml object // from scratch $this->rootNode = SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><' . $rootName . ' />'); } } }
<?php $username = '******'; $twitter_status_url = 'http://twitter.com/statuses/user_timeline/'; $reply = file_get_contents($twitter_status_url . $username . 'xml?count=3'); $xml = SimpleXMLElement($reply); foreach ($xml->children() as $status) { echo $status->text; }