|
|
|
|
|
|
| |
A very simple RSS parser using PHP 5.0.0RC1 and simpleXML.
This parser works fine on my local computer using Apache 1.3.29 (Windows)
and PHP 5.0.0RC1. It is adapted for my own layout using the stylesheet.
| <HTML>
<HEAD>
<TITLE>RSS Feed fra Ingeniרren</TITLE>
<LINK REL=STYLESHEET HREF="../website.css">
</HEAD>
<BODY STYLE="margin-left:100px;margin-right:100px">
<?php
// Function translating Danish utf-8 (BOM) characters
function utfdan($instr)
{
$trans = array("ֳ¦"=>"ז","ֳ¸"=>"ר","ֳ¥"=>"ו","ֳ†"=>"ֶ","ֳ˜"=>"״","ֳ…"=>"ֵ");
$encoded = strtr($instr, $trans);
return $encoded;
}
// Number of items
$items = 15;
// Retrieve XML data
$simple = simplexml_load_file('http://rss.asdf.dk/ing.rss');
// Headline
$headline = utfdan($simple->channel->title);
echo "<h1>$headline</h1>\n";
// Description
$description = utfdan($simple->channel->description);
echo "<DIV CLASS=\"DIV18B\">$description</DIV><BR><BR>\n";
// Show the latest 15 items. The format is RSS 1.0
for($i=0;$i<$items;$i+=1)
{
$title = utfdan($simple->item[$i]->title);
$desc = utfdan($simple->item[$i]->description);
$link = $simple->item[$i]->link; // Translation not necessary
echo "<DIV CLASS=\"DIV18B\"><a href=\"$link\" TARGET=\"_blank\">$title</a></DIV>\n";
echo "<DIV CLASS=\"DIV14N\">$desc</DIV><BR>\n";
}
?>
</BODY>
</HTML>
Adaptation for version 0.91 is easy:
<HTML>
<HEAD>
<TITLE>RSS Feed from BBC</TITLE>
<LINK REL=STYLESHEET HREF="../website.css">
</HEAD>
<BODY STYLE="margin-left:100px;margin-right:100px">
<?
// number of items
$items = 15;
// Retrieve XML data
$simple = simplexml_load_file('http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/world/rss091.xml');
// Headline
echo "<h1>{$simple->channel->title}</h1>\n";
// Time
echo "<DIV CLASS=\"DIV16B\">{$simple->channel->lastBuildDate}</DIV><BR><BR>\n";
// The latest items. The format is RSS 0.91
for($i=0;$i<$items;$i+=1)
{
echo "<DIV CLASS=\"DIV18B\"><a href=\"{$simple->channel->item[$i]->link}\">{$simple->channel->item[$i]->title}</a></DIV>\n";
echo "<DIV CLASS=\"DIV14N\">{$simple->channel->item[$i]->description}</DIV><BR>\n";
}
?>
</BODY>
</HTML> | | |
|
| RSS parser.
Parses RSS into an array. Quick and nasty but does the job.
No checking is done for correct Tags, only correct XML.
PHP4 needed to display result (uses print_r). Categories : PHP, XML, PHP Classes, Rich Site Summary (RSS) | | | Simple newsreader script Categories : PHP, XML, Rich Site Summary (RSS) | | | Avoiding or Detecting high bit characters in a string. Useful when you want to create a valid RSS feed Categories : PHP, Strings, Unicode, Regexps, Rich Site Summary (RSS) | | | PHP Random rss feeds - selects 49 random feeds from an unlimited list and displays them on your website. It's Ideal for those moments when you got 5 minutes and dont know which one of your feeds to read. Categories : PHP, Rich Site Summary (RSS), Arrays | | | XML To Array Categories : PHP, PHP Classes, XML, Arrays | | | A very basic and fast XML parser Categories : PHP, PHP Classes, XML | | | Glossword - glossary compiler Categories : Content Management, PHP, MySQL, XML | | | XML easy parser Categories : PHP, XML | | | Amazon.com API, CURL-REST Parser. Obtain data about Amazon products (PHP5 +) Categories : PHP, Ecommerce, XML, Web Services, CURL | | | MySQL or SQL Query to XML Output Categories : PHP, MySQL, XML, Databases | | | XML Menu Categories : PHP, PHP Classes, Navigation, XML, XSL | | | Dynamic Loading of XML array data into ComboBox and Display XML data using PHP + DOM + Javascript. Categories : PHP, Java Script, DOM XML, XML, Arrays | | | On-the-fly drop down menu from a txt or xml file Categories : PHP, XML, HTML and PHP | | | Directory Listing To XML : Outputs XML File of a Given Directory Listing Categories : PHP, PHP Classes, XML, Directories | | | Trivia Quiz program using XML, XSLT and PHP Categories : PHP, XML, XSLT | |
| | | | Niels Oesten wrote :1070
The function to translate udf-8 of course should be the standard utf8_decode().
| |
|
|
|