Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • PHP FILTERS

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 328
    Comment on it

    1. filter_var():- filter_var() function is used to check if the given variable is a valid IPv6 Address

    <?php
    
    $ip = "2001:cdba:0000:0000:0000:0000:3257:9652";
    
    if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false)
    {
       echo("Valid IPv6 address");
    }
    else
    {
        echo("Not a valid IPv6 address");
    }
    ?>

    output:  Valid IPv6 address

     

     

    2. filter_var():-   filter_var() is used to check if the given variable is url with a querystring.

    <?php
    
    $url = "http://www.findnerd.com";
    
    if (!filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_QUERY_REQUIRED) === false)
    {
        echo("URL is with a querystring");
    }
    else
    {
        echo("URL is not with a querystring");
    }
    
    ?>

    output:  URL is not with a querystring

     
     


    3. filter_var():-   filter_var() is used to check whether the given variable is INT, and between 10 and 100.

    <?php
    
    $int = 111;
    $min = 5;
    $max = 100;
    
    if (filter_var($int, FILTER_VALIDATE_INT, array("options" => array("min_range"=>$min, "max_range"=>$max))) === false)
    {
        echo("Given variable is not within the legal range");
    }
    
    else
    {
        echo("Given variable is within the legal range");
    }
    
    ?>


    output:   Given variable is not within the legal range

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: