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)