$title"); echo("

"); // Remove the first array which includes Title, and User information $rdfinfo = array_shift($newsArray); // Print out the description of the feed and a link to it printf("%s
",$rdfinfo['link'],$rdfinfo['description']); // Print out each song foreach($newsArray as $value) { list($date,$rest) = explode("T",$value['dc:date']); list($time,$rest) = explode("+",$rest); printf("%s %s %s
",$date,$time,htmlspecialchars($value['link']),htmlspecialchars($value['description'])); } // Print out the License information printf("Data available for use under a Creative Commons license.",$rdfinfo['cc:license']['rdf:resource']); echo("

"); // The XML file doesn't exist } else { echo("

AudioScrobbler

"); echo("

AudioScrobbler is not responding.

"); } // Reads XML file into formatted html function readXML($xmlFile) { $xmlParser = xml_parser_create(); xml_parser_set_option($xmlParser, XML_OPTION_CASE_FOLDING, false); xml_set_element_handler($xmlParser, startElement, endElement); xml_set_character_data_handler($xmlParser, characterData); $fp = fopen($xmlFile, "r"); while($data = fread($fp, filesize($xmlFile))){ xml_parse($xmlParser, $data, feof($fp));} xml_parser_free($xmlParser); } // Sets the current XML element, and pushes itself onto the element hierarchy function startElement($parser, $name, $attrs) { global $currentElements, $itemCount, $newsArray; array_push($currentElements, $name); if(($name == "item")||($name == "channel")){$itemCount += 1;} elseif($name == "cc:license") { $currentCount = count($currentElements); $parentElement = $currentElements[$currentCount-2]; $thisElement = $currentElements[$currentCount-1]; $newsArray[$itemCount-1][$thisElement] = $attrs; } } // Prints XML data; finds highlights and links function characterData($parser, $data) { global $currentElements, $newsArray, $itemCount; $currentCount = count($currentElements); $parentElement = $currentElements[$currentCount-2]; $thisElement = $currentElements[$currentCount-1]; if(($parentElement == "item")|| ($parentElement == "channel")|| ($parentElement == "mm:Artist")) { $newsArray[$itemCount-1][$thisElement] = $data;} else{ switch($name){ case "title": break; case "link": break; case "description": break; case "language": break; case "item": break; } } } // If the XML element has ended, it is poped off the hierarchy function endElement($parser, $name) { global $currentElements; $currentCount = count($currentElements); if($currentElements[$currentCount-1] == $name){ array_pop($currentElements);} } ?>