How to make sure your PHP RSS feed reader doesn’t mess up
// March 18th, 2009 // PHP, PHP Tips, Web Development
I was recently working on a custom RSS feed reader where the prior most concern of the client was being able to crop the text with respect to the
- Number of words.
- Numbers of characters.
- Number of sentences.
So a very important measure had to be taken. Since the cropping can end up giving us a broken link if its text is cropped before the </a> tag, our output can end up as a disaster.
So here is a little script that can help you strip off your html tags in such situations.
<?php
$text = "This is a link to <a href='http://www.fahdmurtaza.com/myblog/'>Fahd Murtaza's </a> site!";
echo strip_tags($text, "");
So strip_tags would end up removing anything from the $text. The second parameter of the strip_tags will simply declare any html tags you want to neglect while stripping the text. Off course you will need to deal with them separately in text cropping situations like I had.
Here is one more example.
<?php
$text = '<p>Test paragraph.</p><!-- Comment --> <a href="#fragment">Other text</a>';
echo strip_tags($text);
echo "\n";
// Allow <p> and <a>
echo strip_tags($text, '<p><a>');
?>- Number of words.
- Numbers of characters.
- Number of sentences.
you can get it here.



