Posted By

nerdfiles on 01/06/10


Tagged

php html strip trim whitespace tags


Versions (?)

cleanse html, js, style from form input


 / Published in: PHP
 

  1. function cleanse($input){
  2. $search = array('@]*?>.*?@si', // cleanse js
  3. '@]*?>.*?@siU', // cleanse style
  4. '@<[\/\!]*?[^<>]*?>@si', // cleanse html
  5. '@@' // cleanse CDATA/multi-line comments
  6. );
  7. $text = preg_replace($search, '', $input);
  8. $text = trim($text); // cleanse "whitespace" on left or right
  9. $text = preg_replace('/\\s{2,}/',' ',$text); // cleanse "whitespace" excessive spaces
  10. return $text;
  11. }

Report this snippet  

You need to login to post a comment.