XMPP JavaScript Library

PHP function to clean text for RSS Feed

PHP, Sachin Puri, 2013-03-14 00:14:43

Cleaning text for RSS feed is common problem for any web developer. I have created this function to clean all the special characters from text to include in RSS Feed, this function is working for me.

Just take care of $find variable and keep including all the special characters which are breaking the code.


function clean($content){
    $find=array("’","“","”"); //special characters other then characters starting with & and ending with ;
    $content=htmlspecialchars_decode($content);    
    $content=strip_tags($content);    
    $content=str_replace($find,"",$content);            
    $content=preg_replace('/\&.*\;/','',$content); //Replace all words starting with & and ending with ; with ''
    $content=preg_replace("/(\r?\n){2,}/",'', $content); //Replace all newline characters with ''    
    $content=preg_replace( "/\s+/", " ", $content );//Replace multiple spaces with single space
    $content=trim($content);
    return $content;
}


 

Add Your Comment
   
    Yes! I want to receive all comments by email

  by james thomas on 13-Feb-2019 12:08 am
Great ¡V I should certainly pronounce, impressed with your web site. I had no trouble navigating through all tabs as well as related info ended up being truly simple to do to access. I recently found what I hoped for before you know it at all. Reasonably unusual. Is likely to appreciate it for those who add forums or something, site theme . a tones way for your client to communicate. Excellent task.. Shoreline Amphitheatre tickets
  • Reply
  •  0 Like
  •  0 Dislike
  • Report
  by ryanjackson on 24-Jan-2019 12:20 pm
I saw the difference posts on this website and i am very glad to visit this all. All the posts are very impressive and informative. The post about the PHP function is very informative for me. Thanks for sharing this all. Keep sharing. heavy duty epdm roofing
  • Reply
  •  0 Like
  •  0 Dislike
  • Report
  by Jake on 23-Jan-2019 05:23 pm
You have posted very useful code for RSS feed which i found interesting to read.I will come back to the website to read more similar stuff. gym flooring
  • Reply
  •  0 Like
  •  0 Dislike
  • Report
  by Raj on 26-Jul-2014 03:17 pm
Thanks
  • Reply
  •  0 Like
  •  0 Dislike
  • Report
  by andy on 25-Feb-2014 12:35 am
This is awesome dude, thanks so much
  • Reply
  •  0 Like
  •  0 Dislike
  • Report
  by Rajiv on 13-Jul-2013 12:36 am
Thanks for the help
  • Reply
  •  8 Like
  •  0 Dislike
  • Report