Ciao,
come posso modificare il seguente script affinchè sia l'utente a decidere da quale sito leggere i feed, semplicemente inserendo il link del file xml desiderato?
Codice PHP:
<?php
//set_time_limit(0);
//set your RSS link here !!
$file = "http://www.eurosport.fr/z/tennis/rss.xml";
$rss_channel = array();
$currently_writing = "";
$main = "";
$item_counter = 0;
// setup variable you want to display
function startElement($parser, $name, $attrs) {
global $rss_channel, $currently_writing, $main;
switch($name) {
case "RSS":
case "RDF:RDF":
case "ITEMS":
$currently_writing = "";
break;
case "CHANNEL":
$main = "CHANNEL";
break;
case "IMAGE":
$main = "IMAGE";
$rss_channel["IMAGE"] = array();
break;
case "ITEM":
$main = "ITEMS";
break;
default:
$currently_writing = $name;
break;
}
}
function endElement($parser, $name) {
global $rss_channel, $currently_writing, $item_counter;
$currently_writing = "";
if ($name == "ITEM") {
$item_counter++;
}
}
function characterData($parser, $data) {
global $rss_channel, $currently_writing, $main, $item_counter;
$trashArray = array("é", "è", "Ã", "Â", "ô", "à§", "àª", "à¢", "à¹");
$rightArray = array("é", "è", "à", "", "ô", "ç", "ê", "â", "ù");
for($jer=0;$jer<sizeof($rightArray);$jer++)
{ $data = str_replace($trashArray[$jer], $rightArray[$jer], $data); }
if ($currently_writing != "") {
switch($main) {
case "CHANNEL":
if (isset($rss_channel[$currently_writing])) {
$rss_channel[$currently_writing] .= $data;
} else {
$rss_channel[$currently_writing] = $data;
}
break;
case "IMAGE":
if (isset($rss_channel[$main][$currently_writing])) {
$rss_channel[$main][$currently_writing] .= $data;
} else {
$rss_channel[$main][$currently_writing] = $data;
}
break;
case "ITEMS":
if (isset($rss_channel[$main][$item_counter][$currently_writing])) {
$rss_channel[$main][$item_counter][$currently_writing] .= $data;
} else {
//print ("rss_channel[$main][$item_counter][$currently_writing] = $data
");
$rss_channel[$main][$item_counter][$currently_writing] = $data;
}
break;
}
}
}
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
if (!($fp = fopen($file, "r"))) {
die("could not open XML input");
}
while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);
?>
<html>
<head>
<title>PHP RSS Feed - 4wSearchSripts | We share personnal scripts database ! Software </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="mm_training.css" type="text/css" />
</head>
<body>
<div style="height:100px; overflow:hidden;">
<marquee behavior="scroll" direction="up" scrollamount="1" scrolldelay="1" onMouseOver="this.stop()" onMouseOut="this.start()" style="height:86px;width:100%;">
<span class="txtng_bleu"><u><?php echo $rss_channel["TITLE"]; ?></u></span>
<?php
if (isset($rss_channel["ITEMS"])) {
if (count($rss_channel["ITEMS"]) > 0) { ?><table width="95%" border="0" align="center" cellpadding="4" cellspacing="0" class="txtn_noir"><?php
//for($i = 0;$i < count($rss_channel["ITEMS"]);$i++) {
for($i = 0;$i<3;$i++) {
if($rss_channel["ITEMS"][$i]["CATEGORY"]=="Tennis") {
$combo = explode("
", html_entity_decode($rss_channel["ITEMS"][$i]["DESCRIPTION"]));
$imageArray = explode('"', $combo[0]);
?>
<tr>
<td align="left">[url="<?php echo $rss_channel["]" target="_blank"><?php echo $rss_channel["ITEMS"][$i]["TITLE"]; ?>[/url]
<?php
?></td>
<td align="left">[img]<?php echo $imageArray[1]; ?>[/img]</td>
</tr>
<tr>
<td colspan="2" align="left"><?php echo $combo[1]; ?></td>
</tr>
<?php } }?></table>
<?php
} else {
?><b class="txtng_bleu">Aucun article dans ce flux rss.[/b]<?php
}
}
?></marquee></div>
</body>
</html>
Grazie