Ciao ragazzi ho questo script
Codice PHP:
$insideitem = false;
$tag = "";
$title = "";
$description = "";
$link = "";
function startElement($parser, $name, $attrs) {
global $insideitem, $tag, $title, $description, $link;
if ($insideitem) {
$tag = $name;
} elseif (strtolower($name) == "item") {
$insideitem = true;
}
}
function endElement($parser, $name) {
global $insideitem, $tag, $title, $description, $link;
if (strtolower($name) == "item") {
if($title!="" || $description!=""){;
printf("<div><h2>[url='%s']%s[/url]</h2>",trim(strip_tags($link)),trim(strip_tags($title)),trim(strip_tags($title)));
printf("
%s</p></div>",trim(strip_tags($description)));
}
$title = "";
$description = "";
$link = "";
$insideitem = false;
}
}
function characterData($parser, $data) {
global $insideitem, $tag, $title, $description, $link;
if ($insideitem) {
switch (strtolower($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");
$url = $_REQUEST["url"];
$fp = fopen($url,"r")
or die("Error reading RSS data.");
$x=1;
while ($data = fread($fp, 4096)){
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)));
}
echo $x;
fclose($fp);
xml_parser_free($xml_parser);
Vorrei riuscire ad impostare un numero massimo di articoli da estrarre.
come posso fare?