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 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