PHP Classes

File: filter.php

Recommend this page to a friend!
  Classes of Amer Hendy  >  Filter Text  >  filter.php  >  Download  
File: filter.php
Role: Class source
Content type: text/plain
Description: filter text
Class: Filter Text
Perform several operations to filter text strings
Author: By
Last change: add a description and usage
Date: 7 years ago
Size: 4,522 bytes
 

Contents

Class file image Download
<?php
//////////////////////////////////////////////////////////////////
/// FILTER TEXT LUNIX EGYPT ///
/// version :1 ///
/// author :Amer Hendy - TROJAN ///
/// Location:EGYPT ///
/// SITE:fb.com/amerhendytrojan ///
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
//$filter =new filter();
    //remove tags
      //$text=$filter->removespace($text);
      //$text=$filter->removetags($text);
      //$text=$filter->removeslash($text);
    //replacetags
    //ceonvert to hash
      //$text=$filter->htable($text);
      //$text=$filter->hslash($text);
      //$text=$filter->hhex($text);
    //add tags
      //$text=$filter->newbreak($text);
      //$text=$filter->newslash($text);
    //getreadedtags
      //$text=$filter->htmltags($text);
      //$text=$filter->htmlsource($text);
    // full functions
      //$text=$filter->all($text);
      //$text=$filter->html2text($text);

      //$text=$filter->filter_space($text);
      //$text=$filter->FILTER_NO_NUMBERS($text);
      //$text=$filter->FILTER_AsD($text);
//////////////////////////////////////////////////////////////////
class filter{
  public
$txt_pad = array("\t", "\n", "\r", "\n\n", "\t\t", ' ', ' ', ' ');
  public
$good = array(' ', '<br />', '', '<br /><br />', ' ', ' ', ' ', ' ');
  public
$very_pad = array(
             
'.', "\.", "\..", "\...",
             
">", '<', ".",
             
'&&', '||', '\\',"\\","\/","\"","\'","|", '/',
             
"\&","\!", '\"',"\'",
             
'?', '$', '~', '!', '@', '#', '$', '^',
             
'*', '=', "'", ":", ';', "'", '"', ',',
             
'[', ']', '{', '}', "(",")",
             
'<', '>','%3A', '%2F',
              );
  public function
validate_email($string){
        IF(
filter_var($string, FILTER_VALIDATE_EMAIL)){$string= filter_var($string, FILTER_VALIDATE_EMAIL);return $string;}else{print "0";}
  }
  public function
filter_space($string){
   
$OL= explode(" ",$string);
     if(
count($OL)>1){return TRUE;}else{return FALSE;}
  }
 
//if in numbers
 
public function FILTER_NO_NUMBERS($string){
if (
preg_match("/[0-9]/", $string)) {return TRUE;}else{return FALSE;}
  }
  public function
FILTER_AsD($string){
      if(
preg_match('/[\~\!\`\@\#\$\%\^\&\*\(\)\+\=\{\[\]\}\-\;\:\"\'\<\>\?\,]/',$string)=="1"){
      return
TRUE;
      }else{
      return
FALSE;
      }
if (
preg_match("/[^\.\-\']/", $string)) {return TRUE;}else{print FALSE;}

  }
///////////// remove /////////////////
 
public function removespace($text){return trim($text);}
  public function
removetags($text){return strip_tags($text);}
  public function
removeslash($text){return stripslashes($text);}
////////////// convert to hash //////////
 
public function htable($text){
   
$trans = get_html_translation_table(HTML_ENTITIES);
   
$text=self::htmlsource($text);
    return
strtr($text, $trans);
  }
  public function
hslash($text){return addcslashes($text, 'A..z');}
  public function
hhex($text){return bin2hex($text);}
////////////// add tags /////////////
 
public function newbreak($text){return nl2br($text);}
  public function
newslash($text){return addslashes($text);}

////////////// get readed tags /////////////
 
public function htmltags($text){
    return
htmlspecialchars($text);
  }
  public function
htmlsource($text){
    return
htmlentities($text);
  }
////////////// replace //////////////////////
 
public function replace($type,$text){
    if(
$type == "all1"){return str_replace($this->txt_pad,$this->good,$text);}
    if(
$type == "all2"){return preg_replace("/(<\/?)(\w+)([^>]*>)/"," ",$text);}
    if(
$type == "all3"){return str_replace($this->very_pad,' ',$text);}
    if(
$type == "h2t"){str_replace($this->txt_pad,$this->good,$text);}
  }
///////////// FULL FUNCTIONS /////////////////
 
public function all($text){
   
$text=self::replace("all1",$text);
   
$text=self::replace("all2",$text);
   
$text=self::removespace($text);
   
$text=self::removetags($text);
   
$text=self::replace("all3",$text);
    return
$text;
  }
  public function
html2text($text){
   
$text =self::htmlsource($text);
   
$text =self::replace("h2t",$text);
    return
$text;
  }
}
?>

For more information send a message to info at phpclasses dot org.