I'm trying to use the code in this RSS parser tutorial: http://www.sitepoint.com/article/php-xml-parsing-rss-1-0/4 I have already succeeded in adding the functionality of shortening the news DESCRIPTION to the first x words and then add "...". Now how do you add the option to limit the number of news shown? Say, show only 3 news max.
ah.. that looks a bit confusing, This is jsut a suggestion> I prefer to use lastrss from lastrss.webdot.cz It's (GNU/GPL) and has variables you can set the value of to limit the number of RSS items, I'm sure limiting the string length is easily accomplished. Good Luck'
What I like in the sitepoint rss reader is that everything is in one small file. It's convenient for me because it can be included anywhere in a site very easily. I can just do something like: <div><? include "http://www.domain.com/RSS_reader.php"; ?></div> PHP: Since it's just for use on my website to display my own feed, I don't need more than that. To set a limit to the number of news I was told to "set up a counter variable in the PHP code, incrementing it each time endElement outputs an item. endElement could then be written to only produce output if that counter is below the desired limit." But I don't know how to do that, all my attempts had no success.
OK, I got the solution by adding a counter to endElement: (If anybody is interested) class RSSParser { var $itemCounter = 5; // number of items to show var $insideitem = false; PHP: and integration: function endElement($parser, $tagName) { if ($tagName == "ITEM") { if($this->itemCounter-- < 1) {return;} PHP: Ity works great, and it keeps the code simple. The whole RSS reader is 64 lines of code in ONE file!
Good job ! But does it have cache?? Because the loading time will increase significantly if you have lots of items to show.
Ha, you got a point here: no cache. But as I said, it's only for a specific use on a site and there will never be more than 3 short items to show. (They are shortened by the addition of a function to limit the number of words par items.)
hello all m also using "lastrss" . Using my feeds from 2 blogs. now everything was set except that. i want to limit the characters shown on description. can anyone tell HOW TO LIMIT THE CHARACTERS IN DESCRIPTION ????? Thanks in advance.!
<?php function summary($content, $limit){ $content = explode(' ',$content); for($i=0; $i<$limit; $i++){ $summary[$i] = $content[$i]; } $summary = implode(' ', $summary).'..'; return $summary; } $content = 'This is some demo content. You can put all you want in here, but only the first 3 words will be returned.'; echo summary($content,3); // assign the content and limit ?> PHP: