this works:
http://andres.homelinux.net/myres/scrip ... s2html.php
the code:
Code: Select all
// file test_rss2html.php
<?php
include_once('ext_rss2html.php');
rss2html(0,2,'http://dwlt.net/tapestry/peanuts.rdf');
?>
Code: Select all
<div><a target="_blank" href="http://www.snoopy.com/comics/peanuts/archive/peanuts-20040624.html" >Peanuts for 24 Jun 2004</a><br /><div><img src="http://www.snoopy.com/comics/peanuts/archive/images/peanuts2004305050624.gif" border="0" /></div></div><br>
<div><a target="_blank" href="http://www.snoopy.com/comics/peanuts/archive/peanuts-20040623.html" >Peanuts for 23 Jun 2004</a><br /><div><img src="http://www.snoopy.com/comics/peanuts/archive/images/peanuts2004067340623.gif" border="0" /></div></div><br>
http://andres.homelinux.net/web/
the code (in html article):
Code: Select all
<center>
[PHP]
include_once('../myres/scripts/ext_rss2html.php');
rss2html(0,2,'http://dwlt.net/tapestry/peanuts.rdf');
[/PHP]
</center>
Code: Select all
<center>
<div><a target="_blank" href="" ></a><br /><div></div></div><br>
<div><a target="_blank" href="http://www.snoopy.com/comics/peanuts/archive/peanuts-20040623.html" >Peanuts for 23 Jun 2004</a><br /><div><img src="http://www.snoopy.com/comics/peanuts/archive/images/peanuts2004067340623.gif" border="0" /></div></div><br>
</center>
can't find where the fault is, and i'm starting to go (pea)nuts
cheers
.andre
Code: Select all
<?php
// rss2html.php
$current_tag = '';
$parent_tag = '';
$item_count = 0;
$channel = array();
$image = array();
$item = array();
$textinput = array();
function my_run_xml_parser ($xml_file, $start_tag_function, $end_tag_function, $data_function) {
$xp = xml_parser_create();
xml_set_element_handler ($xp, $start_tag_function, $end_tag_function);
xml_set_character_data_handler ($xp, $data_function);
xml_parser_set_option ($xp, XML_OPTION_CASE_FOLDING, TRUE);
xml_parser_set_option ($xp, XML_OPTION_SKIP_WHITE, TRUE);
if (!($fp = fopen ($xml_file, "r"))) { die ("Could not read $xml_file"); }
while ($xml = fread ($fp, 4096)) { if (!xml_parse ($xp, $xml, feof ($fp))) {
die("XML parser error: " . xml_error_string (xml_get_error_code ($xp)));}
}
xml_parser_free ($xp);
}
function my_rss_tag_start ($parser, $tag_name, $attributes) {
global $current_tag, $parent_tag;
$tag_name = strtolower ($tag_name);
$current_tag = $tag_name;
if ($tag_name == 'channel' || $tag_name == 'item' || $tag_name == 'image' || $tag_name == 'textinput') {
$parent_tag = $tag_name;
}
}
function my_rss_tag_end ($parser, $tag_name) {
global $current_tag, $parent_tag, $item_count;
$tag_name = strtolower ($tag_name);
$current_tag = '';
if ($tag_name == 'channel' || $tag_name == 'item' || $tag_name == 'image' || $tag_name == 'textinput') {
$parent_tag = '';
if ($tag_name == 'item') {
$item_count++;
}
}
}
function my_rss_character_data ($parser, $data) {
global $current_tag, $parent_tag, $item, $channel, $image, $textinput, $item_count, $output;
$data = trim (htmlspecialchars ($data));
if ($current_tag == 'title' || $current_tag == 'link' || $current_tag == 'description' || $current_tag == 'url' || $current_tag == 'width' || $current_tag == 'height' || $current_tag == 'name' || $current_tag == 'guid' || $current_tag == 'content:encoded') {
$current_tag = strtolower ($current_tag);
if ($parent_tag == 'item') {
$item[$item_count][$current_tag] .= $data;
}
else if ($parent_tag == 'channel') {
$channel[$current_tag] .= $data;
}
else if ($parent_tag == 'image') {
$image[$current_tag] .= $data;
}
else if ($parent_tag == 'textinput') {
$textinput[$current_tag] .= $data;
}
}
}
function rss2html($top, $headers, $rss_uri){
global $current_tag,$parent_tag,$item_count,$channel,$image,$item,$textinput;
my_run_xml_parser ($rss_uri, 'my_rss_tag_start', 'my_rss_tag_end', 'my_rss_character_data');
if (!empty ($image)) {
$channel_image = "<img border=\"0\" src=\"" . $image['url'] . "\" width=\"" . $image['width'] . "\" height=\"" . $image['height'] . "\" alt=\"" . $channel_title . " button\" title=\"" . $image['description'] . "\" class=\"floatl\" style=\"margin-right:5px;\" />";
}
$channel_title = $channel['title'];
$top_text = "<div><a target=\"_blank\" href=\"" . $channel['link'] . "\">" . $channel_image . $channel_title . "</a><br /><font>".$channel['description']."</font></div><br>";
if ($headers==0) $number_items = sizeof ($item);
else $number_items = $headers;
for ($i = 0; $i < $number_items; $i++) {
$current_link = $item[$i]['guid'];
if (!empty ($item[$i]['link'])) {
$current_link = $item[$i]['link'];
}
$current_description = html_entity_decode ($item[$i]['description']);
if (!empty ($item[$i]['content:encoded'])) {
$current_description = $item[$i]['content:encoded'];
}
$cdata_test = strpos ($current_description, "<![CDATA[");
if ($cdata_test != 0) {
$current_description = html_entity_decode ($current_description);
}
$item_title = $item[$i]['title'];
$output .= "<div><a target=\"_blank\" href=\"" . $current_link . "\" " . $open_new_window . ">" . $item_title . "</a><br /><div>" . $current_description . "</div></div><br>\n";
}
if (!empty ($textinput['link']) && !empty ($textinput['name'])) {
if (empty ($textinput['title'])) {
$textinput['title'] = 'Search';
}
$output .= "<h2>" . $textinput['title'] . "</h2>";
$output .= "<form action=\"" . $textinput['link'] . "\" method=\"get\">\n<input type=\"text\" name=\"" . $textinput['name'] . "\" />\n<input type=\"submit\" value=\"Search\" />\n</form>\n";
}
if ($top==1) echo $top_text;
echo $output;
}
?>