WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Simple newsreader script
Categories : PHP, XML, Rich Site Summary (RSS) Click here to Update Your Picture
Ben Yacoub Hatem
Date : Mar 12th 2005
Grade : 5 of 5 (graded 1 times)
Viewed : 4687
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Ben Yacoub Hatem
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

<?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("`&lt;item[^&gt;]*&gt;.*?&lt;/item(s?)&gt;`si",
$row, $rowitem ) ) {
        $item = $rowitem[0];
        $res = "";
        for( $i = 0; $i &lt; count($item) - 1; $i++   ) {

            if (trim($item[$i])!=`` and
!ereg(`&lt;items`,$item[$i])) {
              eregi(`&lt;title&gt;(.*)&lt;/title&gt;`, $item[$i], $title );
              eregi(`&lt;link&gt;(.*)&lt;/link&gt;`, $item[$i], $url );
              $res .= `&lt;a href="` . str_replace("&amp;","&",$url[1]) . `"&gt;` . $title[1]
. `&lt;/a&gt; &lt;br /&gt;`;   
            }    
        }
    }
    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(`&lt;description&gt;(.*)&lt;/description&gt;`, $item[$i], $description );
              if ($description != "" && $description[1] != $title[1])
                  $res .= `&lt;div&gt;`. $description[1] .`&lt;/div&gt;`;