Snippets v2

Languages
My Snippets

Filter out HTML code from String Login or Register to Bookmark this snippet

Description PHP

This function filters out ALL tags! Does not remove text between tags (ie: <p>this text is not removed</p>) So, any <style> tags would be removed, but the css inside them would remain. something to keep in mind.

The Code Download
  1. <?php
  2. function FilterHTML ($text) {
  3.     $matches = array();
  4.     preg_match_all("'<stript[/!]*?[^<>]*?</script>'si",$text,$matches);
  5.     for ($x=0;$x<count($matches);$x++) {
  6.         $string = $matches[$x];
  7.         $changed = str_replace($string,"",$text);
  8.     }
  9.  
  10.     $matches = array();
  11.     preg_match_all("'<style[/!]*?[^<>]*?</style>'si",$text,$matches);
  12.     for ($x=0;$x<count($matches);$x++) {
  13.         $string = $matches[$x];
  14.         $changed = str_replace($string,"",$text);
  15.     }
  16.  
  17.     $matches = array();
  18.     preg_match_all("'<[/!]*?[^<>]*?>'si",$text,$matches);
  19.     for ($x=0;$x<count($matches);$x++) {
  20.         $string = $matches[$x];
  21.         $changed = str_replace($string,"",$text);
  22.     }
  23.  
  24.     for ($x=100;$x>0;$x--) {
  25.         $white = '';
  26.         for ($y=1;$y<$x;$y++) {
  27.             $white .= ' ';
  28.         }
  29.         $changed = str_replace($white,' ',$changed);
  30.     }
  31.  
  32.     for ($x=1;$x<3;$x++) {
  33.         $changed = str_replace("nnnn","n",$changed);
  34.         $changed = str_replace("nnn","n",$changed);
  35.         $changed = str_replace("nn","n",$changed);
  36.     }
  37.  
  38.     return $changed;
  39. }
  40. ?>
Credits Contact JC

Added by JC on 11th November, 2007

Comments

There are no comments about this snippet.

Post Comment HTML is allowed

You must be registered and logged in to post a comment.

Login here to post a comment