long time listener first time caller…
I have this function (I don;t recall where its from sorry, I’ve had it forever)
It simply parses an XML feed and creates a list of upcoming gigs – it was working fine but changing to a new server with latest PHP and it isn’t working.
function parseRSS($url) {
$feedeed = implode('', file($url));
$parser = xml_parser_create();
xml_parse_into_struct($parser, $feedeed, $valueals, $index);
xml_parser_free($parser);
foreach($valueals as $keyey => $valueal){
if($valueal['type'] != 'cdata') {
$item[$keyey] = $valueal;
}
}
$i = 0;
foreach($item as $key => $value){
if($value['type'] == 'open') {
$i++;
$itemame[$i] = $value['tag'];
} elseif($value['type'] == 'close') {
$feed = $values[$i];
$item = $itemame[$i];
$i--;
if(count($values[$i])>1){
$values[$i][$item][] = $feed;
} else {
$values[$i][$item] = $feed;
}
} else {
$values[$i][$value['tag']] = $value['value'];
}
}
return $values[0];
}
$xml = parseRSS("http://acousti.co/feeds/artist/AboveThem");
$count = 0;
foreach($xml['RSS']['CHANNEL']['ITEM'] as $item) {
$pubDate = $item['PUBDATE'];
$pubDateFormatted = date('D j M Y', strtotime($pubDate));
echo("<a href=\"{$item['LINK']}\" target=\"_blank\" class=\"indexBoxNews\">{$item['DESCRIPTION']}{$link}</a>
<p class=\"rss-date\">$pubDateFormatted</p>");
if (++$count == 5) break;
}
Does anyone know why it may have stopped working – the code was written pre-PHP5 that’s for sure so maybe it’s a compatibility issue?
Any help very much appreciated 🙂
Rob
Since you’re now on PHP 5, you may want to just rewrite the code using simplexml. PHP4, without adding additional libraries, didn’t have a good easy way of dealing with XML, but now with PHP 5, your code should be a fraction of what you used for PHP 4.
Try this: