Forum
How to limit the description size in RSS feed?
2010-09-09 23:59:41
JDO2010
Is there a way to limit the number of characters or words that will be shown by rsslib? Even better if it would put a "..." at the end of the description that is shown if it would need to cut if off.
Jeremy
2010-09-10 11:32:40
scriptol
In RSS_Tags
After:
$description = $tnl->firstChild->textContent;you can add:
$description = substr($description, 0, 150)."...";Replace 150 by the size you want. This could be improved by a regular expression to break the text after a dot. I'll try to retrieve the code I have already somewhere.
2010-09-10 16:41:35
JDO2010
Thanks for the help. It worked out great.
2010-09-15
Duc
I've been using your lib for business purpose, could you please give me the permission to modify it?
I need to add a function like this:
function shortstring ($var, $len) { if (strlen ($var) < $len) return $var; if (preg_match ("/(.{1,$len})\s/", $var, $match)) return $match [1] . ".."; else return substr ($var, 0, $len) . ".."; }into rsslib.php in order to shorten the description, and I will modify the RSS_Display() like below.
if ($description != false) { $shortdesc = shortstring($description, 30); $page .= "$shortdesc"; }I'll try to find another way if my permission won't be granted. With regards, Duc.
2010-09-15
Scriptol
Hello,
Yes, this improves the quality of the display and I should have used a similar formula to do it. Of course, you can change the code.
Best regards,
D. Sureau.