|
|
|
| помогите школьнику плз обработать rss файл
в школе задали, а я не секу сильно.
<?xml version='1.0' encoding='windows-1251'?>
<rss version="2.0">
<channel>
<title>Название1</title>
<link>http://some1.cxm/</link>
<description>Описание1</description>
<image>
<url>http://some2.cxm/img.gif</url>
<title>Название2</title>
<link>http://some2.cxm/</link>
</image>
<item>
<title>Название3</title>
<pubDate>Thu, 02 Feb 2006 10:22:00 +0200</pubDate>
<link>http://some3.cxm/</link>
<description>Описание3</description>
<category>Категория3</category></item>
<item>
<title>Название4</title>
<pubDate>Thu, 02 Feb 2006 10:22:00 +0200</pubDate>
<link>http://some4.cxm/</link>
<description>Описание4</description>
<category>Категория3</category></item>
<item>
<title>Название4</title>
<pubDate>Thu, 02 Feb 2006 10:22:00 +0200</pubDate>
<link>http://some4.cxm/</link>
<description>Описание4</description>
<category>Категория4</category></item>
<item>
</channel>
</rss>
|
усли возможно то в стиле http://www.softtime.ru/forum/files/639-20041229052709.zip автор antf | |
|
|
|
|
|
|
|
для: школьник
(06.02.2006 в 20:55)
| | А вопрос где? В чём требуется помощь? | |
|
|
|
|
|
|
|
для: cheops
(07.02.2006 в 03:19)
| | если делать с помощью скрипта antf , то темы не соответствуют ссылкам и телу новости(<description>), и первая новость выводит без описания, а последня новость выводит без темы. | |
|
|
|
|
|
|
|
для: школьник
(07.02.2006 в 11:52)
| | А какое действие производится - необходимо вывести информацию, разобрав XML-файл, поместить её в текстовый файл или что-то ещё? | |
|
|
|
|
|
|
|
для: cheops
(07.02.2006 в 13:50)
| | да , просто вывести,
поле putdate вывести только время | |
|
|
|
|
|
|
|
для: школьник
(07.02.2006 в 11:52)
| | если такой простейший скрипт подойдёт могу скинуть
http://pg.proc.ru/rss_reader.php | |
|
|
|
|
|
|
|
для: streloc
(07.02.2006 в 15:17)
| | дай плз поглядеть твой скриптик | |
|
|
|
|
|
|
|
для: школьник
(09.02.2006 в 14:11)
| | воще конешна хотелось чтобы в помощь студентам, новичкам, в учебник php - softime, добавили тему как работать с rss и xml. Я думаю что очень многие посетители softtime.ru обрадуютсья такой новинки | |
|
|
|
|
|
|
|
для: школьник
(09.02.2006 в 14:11)
| |
<?php
set_time_limit(0);
$file = "http://cnews.ru/news.xml";
$rss_channel = array();
$currently_writing = "";
$main = "";
$item_counter = 0;
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;
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<br>");
$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);
// output as HTML
print ("<html><head><title>PHP RSS Reader</title></head><body>");
if (isset($rss_channel["IMAGE"])) {
print ("<a href=\"" . $rss_channel["LINK"] . "\" target=\"_blank\"><img border=\"0\" src=\"" . $rss_channel["IMAGE"]["URL"] . "\" align=\"middle\" alt=\"" . $rss_channel["IMAGE"]["TITLE"] . "\"></a> <font size=\"5\">" . $rss_channel["TITLE"] . "</font><br><br>");
} else {
print ("<font size=\"5\">" . $rss_channel["TITLE"] . "</font><br><br>");
}
print ("<i>" . $rss_channel["DESCRIPTION"] . "</i><br><br>");
if (isset($rss_channel["ITEMS"])) {
if (count($rss_channel["ITEMS"]) > 0) {
for($i = 0;$i < count($rss_channel["ITEMS"]);$i++) {
print ("\n<table width=\"100%\" border=\"0\"><tr><td width=\"100%\"><a href=\"" . $rss_channel["ITEMS"][$i]["LINK"] . "\" target=\"_blank\"><h4>" . $rss_channel["ITEMS"][$i]["TITLE"] . "</h4></a></b>");
print ("<i>" . html_entity_decode($rss_channel["ITEMS"][$i]["DESCRIPTION"]) . "</i>");
print ("</td></tr></table><br>");
}
} else {
print ("<b>There are no articles in this feed.</b>");
}
}
print ("</body></html>");
?>
|
| |
|
|
|
|
|
|
|
для: streloc
(09.02.2006 в 16:23)
| | Отличненько! Спасибо большое!
Думаю тему можно закрыть | |
|
|
|