Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • PHP filters to Sanitize and Validate data

    • 0
    • 2
    • 2
    • 2
    • 0
    • 0
    • 0
    • 0
    • 492
    Comment on it

    Hello Readers ,

    Today we will going to understand the concept of PHP filters to Sanitize and Validate data.

    PHP filters are used to validate and sanitize external input.

    Validating data = Determine if the data is in proper form.

    Sanitizing data = Remove any illegal character from the data.

    So in order to user the PHP filters their is a PHP function called "filter_var()".

    Let's understand how we can use this function.

    Suppose we are going to Sanitize and Validate a specific URL.

    <?php
    $url = "http://www.findnerd.com";
    
    // Remove all illegal characters from a url
    $url = filter_var($url, FILTER_SANITIZE_URL);
    
    // Validate url
    if (!filter_var($url, FILTER_VALIDATE_URL) === false) {
         echo("$url is a valid URL");
    } else {
         echo("$url is not a valid URL");
    }
    ?>
    

    Output will be : http://www.findnerd.com is a valid URL.

    Good Luck!

 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: