Status
Not open for further replies.

xifyhosting

Active Member
35
2011
9
0
Hello,

I dont know about you but for me if their is an easy and shorter way of coding in PHP then i will se it. To day i made a small filter function (untested)

PHP:
<?php
/**
  * @authors Jordan Hall <nukezilla@hotmail.co.uk> & JokerHacker
  * @Acknowledge S.C. Chen <http://sourceforge.net/projects/simplehtmldom/>
  * @Contributions Bennett Treptow <Upload class>
  * @SpecailThanks Bennett Treptow  for teching me Comparison Operators
  * @version 0.1
  * @copyright 2012 Sim*****HP
  */
    function filter ($type, $input, $min = null, $max = null)
    {
        $type = strtolower($type);
        if ($type == "string")
        {
         if($min == null && $max == null){
         {
             return (filter_var($input, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH)) ? $input:false;
         else
         {
             if (strlen($input) < $min || (strlen($input) > $max )
            {
                 return false;
            }
            else
            {
                return $input;
            }
         }
        }
        elseif ($type == "int")
        {
         return (filter_var($input, FILTER_SANITIZE_NUMBER_INT)) ? $input:false;
        }
        elseif ($type == "url")
        {
         return (filter_var($input, FILTER_SANITIZE_URL)) ? $input:false;
        }
        elseif ($type == "ip")
        {
         if (filter_var($input, FILTER_VALIDATE_IP)) ? $input:false;
        }
        elseif ($type == "email")
        {
         if (filter_var($input, FILTER_SANITIZE_EMAIL)) ? $input:false;
        }
    }
?>
?>
Regards,
Jordan
 
Last edited:
Status
Not open for further replies.
Back
Top