Lo devi modificare così:
Codice PHP:
<?php
$insideitem = false;
$tag = '';
$title = '';
$description = '';
$link = '';
function startElement($parser, $name, $attrs) {
global $insideitem, $tag, $title, $description, $link;
if ($insideitem) {
$tag = $name;
} elseif ($name == 'ITEM') {
$insideitem = true;
}
}
function endElement($parser, $name) {
global $insideitem, $tag, $title, $description, $link;
if ($name == 'ITEM') {
printf('<p><b><a href=\'%s\'>%s</a></b><br>',
trim($link),trim($title));
printf('%s</p>'."\n",trim($description));
$title = '';
$description = '';
$link = '';
$insideitem = false;
}
}
function characterData($parser, $data) {
global $insideitem, $tag, $title, $description, $link;
if ($insideitem) {
switch ($tag) {
case 'TITLE':
$title .= $data;
break;
case 'DESCRIPTION':
$description .= $data;
break;
case 'LINK':
$link .= $data;
break;
}
}
}
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, 'startElement', 'endElement');
xml_set_character_data_handler($xml_parser, "characterData");
$fp = fsockopen("www.gazzetta.it", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET /rss/Calcio.xml HTTP/1.1\r\n";
$out .= "Host: www.gazzetta.it\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
$header = '';
do{
$header .= fgets($fp, 128);
}while(strpos($header, "\r\n\r\n") === false);
while ($data = fgets($fp, 1024)) {
xml_parse($xml_parser, $data, feof($fp))
or die(sprintf('XML error: %s at line %d',
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
fclose($fp);
}
xml_parser_free($xml_parser);
?>