I need some help here.
I am developing a class of data sanitizer. It has many methods, but only one will be used per users.
However this "super-method" don't pass the others "simple-methods" sequentially.
Example:
Method #1: NoSpaces (remove all spaces)
Method #2: HTMLEntities (Convert all special characters to real HTML)
Super-Method: Apply Method #1 in the "unique" parameter and redirect the actual value to apply the Method #2, then return.
Use: print Super_Method( "& #032;µ& #032;" ); //Example, but with no space between "&" and "#032"
My tentative of code is:
<?php
class Clean
{
private $warnings = array();
private $errors = array();
private $get_magic_quotes = FALSE;
private $entities = TRUE;
public $input;
private $data;
function __construct()
{
// Error Alert
error_reporting(E_ALL);
// The current value of magic_quotes_gpc
$this -> get_magic_quotes = get_magic_quotes_gpc();
}
//-------------------------------------------------------------------------
// Request data sanitizer
//-------------------------------------------------------------------------
// Removing fake spaces
public function NoSpaces( $data )
{
$data = str_replace( " ", " ", $data );
$data = str_replace( " ", " ", $data );
return $data;
}
// Only allow UNICODE Characters
public function Unicode( $data )
{
return preg_replace( "/&#([0-9]+);/s", "&#\\1; ", $data );
}
// Converting New Lines to Line Breaks
public function nl2br( $data )
{
return nl2br( $data );
}
// Removing auto-quotes from variables
public function MagicQuotes( $data )
{
if( ! $this -> get_magic_quotes )
{
$data = stripslashes( $data );
}
return $data;
}
// Converting specialchars and entities to real HTML
public function HTMLEntities( $data )
{
if( $this -> entities )
{
$this -> data = htmlentities( $data );
}
}
// Striping Tags
public function StripTags( $data, $tags = array() )
{
$args = func_get_args();
$data = array_shift( $args );
$tags = func_num_args() > 2 ? array_diff( $args, array( $data ) ) : ( array ) $tags;
foreach ( $tags as $tag )
{
if( preg_match_all( '/<' . $tag . '[^>]*>(.*)<\/' . $tag . '>/iU', $data, $found ) )
{
$data = str_replace( $found[ 0 ], $found[ 1 ], $data );
}
}
return $data;
}
// Check URL existence
public function URLChecker( $data )
{
if( ini_get( 'allow_url_fopen' ) )
{
return ( $open = fopen( $data, 'r' ) ) === FALSE ? FALSE : fclose( $open );
}
else
{
$warnings[] = '<b>allow_url_fopen</b> is deactivated. Please, check your <b>php.ini</b> and try again later.';
}
}
// EGPCS Sanitizer
public function parseData()
{
$arrMethods = array(
"HTMLEntities"
);
foreach ($arrMethods as $sNameMethod) {
call_user_func_array(array($this, $sNameMethod), $this->data);
}
return $this -> data;
}
}
$Clean = new Clean;
print $Clean -> parseData( "&" );
But no works.Help me, please and sorry if my English is horrible.
[]'s
