Search
 
SCRIPT & CODE EXAMPLE
 

PHP

codeigniter sanitize input field

// THIS HELPER METHOD SANITIZES INPUT FIELDS
function sanitize($input = '')
    {
        // AT FIRST TRIMMING THE INPUT, REMOVING THE WHITE SPACES.
        $trimmed_input = trim(preg_replace('/ss+/', ' ', $input));
        $type = gettype($trimmed_input);
        if ($type == "integer") {
            $sanitized_input = filter_var($trimmed_input, FILTER_SANITIZE_NUMBER_INT);
        } elseif ($type == "double") {
            $sanitized_input = filter_var($trimmed_input, FILTER_SANITIZE_NUMBER_FLOAT);
        } else { // LETS ASSUME IT IS A STRING
            // $sanitized_input = filter_var($trimmed_input, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH | FILTER_FLAG_STRIP_BACKTICK);
            $sanitized_input = html_entity_decode(htmlspecialchars($trimmed_input));
        }

        return $sanitized_input;
    }
Comment

PREVIOUS NEXT
Code Example
Php :: laravel custom exception handler 
Php :: display data from two dimensional array in vew laravel 
Php :: signup api in laravel 
Php :: Laravel - Send mail using mail class 
Php :: where clause in laravel 
Php :: laravel debugbar false 
Php :: php localhost 
Php :: laravel update multiple select query 
Php :: laravel belongstomany prevent duplicates attach 
Php :: use php artisan command through controller 
Php :: rendering json in laravel 
Php :: composer create project laravel with version 
Php :: Laravel route not calling function of controller 
Php :: if statement in laravel blade 
Php :: api resource create in laravel 
Php :: php configuration in apache server 2.4 
Php :: php concatenation with a space 
Php :: custom pagination in laravel 
Php :: what is lang in laravel 
Php :: laravel textarea value 
Php :: wp_query custom post type 
Php :: install multiple php versions windows xampp 
Php :: seo_url.php location opencart 
Php :: on keyup jquery for search php on basis of class name 
Php :: change default route laravel 
Php :: get percentage rating in laravel 
Php :: mixed content laravel form target 
Php :: Use external variable in array_filter 
Php :: include navbar or part in layout in laravel blade template 
Php :: Laravel Secured Password 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =