|
|
|
| <?php
/**
* Simple newsfeed script work for both RSS and RDF
*
* @update fixed problem in url
* @param $newsfeed
* @return
**/
function newsfeed($newsfeed){
$row = @implode('',@file($newsfeed));
if(
preg_match_all("'<item[^>]*>.*?</item(s?)>'si",
$row, $rowitem ) ) {
$item = $rowitem[0];
$res = "";
for( $i = 0; $i < count($item) - 1; $i++ ) {
if (trim($item[$i])!='' and
!ereg('<items',$item[$i])) {
eregi('<title>(.*)</title>', $item[$i], $title );
eregi('<link>(.*)</link>', $item[$i], $url );
$res .= '<a href="' .
str_replace("&","&",$url[1]) . '">' . $title[1]
. '</a> <br />';
}
}
}
return $res;
}
echo newsfeed('http://www.weberdev.com/RSS/LatestExamples.xml');
?> | | |
|
| 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) | | | RSS parser using PHP5 and simpleXML Categories : Rich Site Summary (RSS), PHP, XML | | | 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 | | | Amazon.com API, CURL-REST Parser. Obtain data about Amazon products (PHP5 +) Categories : PHP, Ecommerce, XML, Web Services, CURL | | | XML easy parser Categories : PHP, XML | | | MySQL or SQL Query to XML Output Categories : PHP, MySQL, XML, Databases | | | XML Menu Categories : PHP, PHP Classes, Navigation, XML, XSL | | | Trivia Quiz program using XML, XSLT and PHP Categories : PHP, XML, XSLT | | | 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 | |
| | | | Sanjoy Roy wrote : 1287
I could not see the result of the http://www.weberdev.com/RSS/LatestExamples.xml RSS. The browser does not shows up anything it`s blank.
I have checked the links, it`s not broken.
Please reply.
Thanks,
Sanjoy Roy
| | | | Ben Yacoub Hatem wrote : 1288
It`s working fine, maybe you don`t have permission to use file(), remove the @ in code and you`ll see the error message.
And this one fix problem in url :
function newsfeed($newsfeed){
$row = @implode(``,@file($newsfeed));
if( preg_match_all("`<item[^>]*>.*?</item(s?)>`si",
$row, $rowitem ) ) {
$item = $rowitem[0];
$res = "";
for( $i = 0; $i < count($item) - 1; $i++ ) {
if (trim($item[$i])!=`` and
!ereg(`<items`,$item[$i])) {
eregi(`<title>(.*)</title>`, $item[$i], $title );
eregi(`<link>(.*)</link>`, $item[$i], $url );
$res .= `<a href="` . str_replace("&","&",$url[1]) . `">` . $title[1]
. `</a> <br />`;
}
}
}
return $res;
}
| | | | Rahul Puranik wrote : 1289
I think PHP`s builtin expat parser would have been more useful than parsing the data with ereg or preg
| | | | Ben Yacoub Hatem wrote : 1290
It`s not about performance, it`s just another way to do it with regular expression :-)
| | | | Ronny Sherer wrote :1296
Add the following lines for description:
eregi(`<description>(.*)</description>`, $item[$i], $description );
if ($description != "" && $description[1] != $title[1])
$res .= `<div>`. $description[1] .`</div>`;
| |
|
|
|