<?php
/*function toId($var)
{
    $unsafe = array('\'', '\"');
    $var =  str_replace($unsafe, '', $var);
    return (string)mysql_real_escape_string($var);
}

function toAlfaNum($var)
{
    if(ctype_alnum($var))
        return $var;
    return preg_replace('/^[a-zA-Z0-9]+$/', '', $var);
}



function toString($var)
{
    //print "//tukaj se";
    return (string)mysql_real_escape_string($var);
}

function toInt($var)
{
    $var1 = array();
    if(is_array($var))
    {
        
        foreach($var as $key => $val)
        {
            $var1[$key] = intval($val);
        }
        return $var1;
    }
    return intval((int)$var);
}

function toJson($var)
{
    json_decode($var);
    
    if(json_last_error() == JSON_ERROR_NONE)
    {
        return $var;
    }
    else
        return "";
}
*/
class convert 
{
    public static function toId($var)
    {
        $unsafe = array('\'', '\"');
        $var =  str_replace($unsafe, '', $var);
        return (string)mysql_real_escape_string($var);
    }
    
    public static function toAlfaNum($var)
    {
        if(ctype_alnum($var))
            return $var;
        return preg_replace('/^[a-zA-Z0-9]+$/', '', $var);
    }
    
    
    
    public static function toString($var)
    {
        return (string)mysql_real_escape_string($var);
    }
    
    public static function toInt($var)
    {
        $var1 = array();
        if(is_array($var))
        {
            
            foreach($var as $key => $val)
            {
                $var1[$key] = intval($val);
            }
            return $var1;
        }
        return intval((int)$var);
    }
    
    public static function toJson($var)
    {
        json_decode($var);
        
        if(json_last_error() == JSON_ERROR_NONE)
        {
            return $var;
        }
        else
            return "";
    }
    
    public static function toBool($var)
    {
        return filter_var($var, FILTER_VALIDATE_BOOLEAN);
    }
    
    
}

?>