Return to Snippet

Revision: 35365
at November 12, 2010 04:37 by sadus


Updated Code
function clean($string,$type){
        switch ($type){
            case "int":
                return filter_var(filter_var($string, FILTER_SANITIZE_NUMBER_INT), FILTER_VALIDATE_INT);
            case "string":
                return filter_var($string, FILTER_SANITIZE_STRING);
            case "sql":
                return mysql_real_escape_string($string);
                break;
            case "email":
                return filter_var(filter_var($string, FILTER_SANITIZE_EMAIL), FILTER_VALIDATE_EMAIL);
                break;
            case "url":
                return filter_var(filter_var($string, FILTER_SANITIZE_URL), FILTER_VALIDATE_URL);
                break;
            case "ip":
                return filter_var(filter_var($string, FILTER_SANITIZE_IP), FILTER_VALIDATE_IP);
                break;
            default:
                return 0;
                break;
        }
    }

Revision: 35364
at November 6, 2010 01:23 by sadus


Updated Code
function clean($string,$type){
        switch ($type){
            case "int":
                return filter_var(filter_var($string, FILTER_SANITIZE_NUMBER_INT), FILTER_VALIDATE_INT);
            case "string":
                return filter_var($string, FILTER_SANITIZE_STRING);
            case "sql":
                return mysql_real_escape_string($string);
                break;
            case "email":
                return filter_var(filter_var($string, FILTER_SANITIZE_EMAIL), FILTER_VALIDATE_EMAIL);
                break;
            case "url":
                return filter(filter_var($string, FILTER_SANITIZE_URL), FILTER_VALIDATE_URL);
                break;
            case "ip":
                return filter_var(filter_var($string, FILTER_SANITIZE_IP), FILTER_VALIDATE_IP);
                break;
            default:
                return 0;
                break;
        }
    }

Revision: 35363
at November 6, 2010 01:21 by sadus


Initial Code
function clean($string,$type){
        if(DEBUG){
            debug(debug_backtrace());
        }
        switch ($type){
            case "int":
                return filter_var(filter_var($string, FILTER_SANITIZE_NUMBER_INT), FILTER_VALIDATE_INT);
            case "string":
                return filter_var($string, FILTER_SANITIZE_STRING);
            case "sql":
                return mysql_real_escape_string($string);
                break;
            case "email":
                return filter_var(filter_var($string, FILTER_SANITIZE_EMAIL), FILTER_VALIDATE_EMAIL);
                break;
            case "url":
                return filter(filter_var($string, FILTER_SANITIZE_URL), FILTER_VALIDATE_URL);
                break;
            case "ip":
                return filter_var(filter_var($string, FILTER_SANITIZE_IP), FILTER_VALIDATE_IP);
                break;
            default:
                return 0;
                break;
        }
    }

Initial URL

                                

Initial Description

                                

Initial Title
data sanitization

Initial Tags
php, data

Initial Language
PHP