Sanitize Key : Lowercase Accentless $string, Special Characters $replacement

function sanitize_key( $string, $replacement = '_' )
{
    // Lowercase and remove accents
    $string = htmlentities( trim( strtolower( strval( $string ) ) ), ENT_NOQUOTES );
    $string = preg_replace( '/&([a-z])(?:acute|cedil|caron|circ|grave|orn|ring|slash|th|tilde|uml);/', '$1', $string );
    $string = preg_replace( '/&([a-z]{2})(?:lig);/', '$1', $string );
    $string = preg_replace( '/&[^;]+;/', $replacement, $string );
    // Replace non-alphanumeric characters
    return preg_replace( '/[^a-z0-9]+/', $replacement, $string );
}

Sanitize $value According to its $type

function sanitize( $value, $type = null )
{
    // Recursive sanitation for arrays and objects
    if ( is_array( $value ) || is_object( $value ) ) {
        $output = array();
        foreach ( (array) $value as $k => $v ) {
            $k = sanitize_key( $k );
            $output[$k] = sanitize( $v, $type );
        }
        return $output;
    }

    // Default to value's actual type
    if ( ! $type ) { $type = gettype( $value ); }

    switch( strtolower( $type ) )
    {
        case 'boolean':
            return boolval( $value );
        case 'integer':
        case 'number':
            return intval( $value );
        case 'double':
        case 'float':
            return floatval( $value );
        case 'null':
            return null;
        case 'resource':
            return $value;
        case 'url':
            return filter_var( rtrim( $value, '/' ), FILTER_SANITIZE_URL );
        case 'email':
            return filter_var( substr( $value, 0, 254 ), FILTER_SANITIZE_EMAIL );
        default:
            // String
            return filter_var( $value, FILTER_SANITIZE_STRING );
    }
}