Monday, November 7, 2016

Validate Form Data

Strip unnecessary characters (extra space, tab, newline) from the user input data (with the PHP trim() function)
Remove backslashes (\) from the user input data (with the PHP stripslashes() function)
 function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}

http://www.w3schools.com/php/php_form_validation.asp
 -------------------------------------------------
 Sanitize a String
The following example uses the filter_var() function to remove all HTML tags from a string:
 ...
<?php
$str = "<h1>Hello World!</h1>";
$newstr = filter_var($str, FILTER_SANITIZE_STRING);
echo $newstr;
?>
...
<?php
$url = "http://www.w3schools.com";
// Remove all illegal characters from a url$url = filter_var($url, FILTER_SANITIZE_URL);
// Validate urlif (!filter_var($url, FILTER_VALIDATE_URL) === false) {
    echo("$url is a valid URL");
} else {
    echo("$url is not a valid URL");
}
?>
 http://www.w3schools.com/php/php_filter.asp
 ------------------------------------
 int preg_match ( string $pattern , string $subject [, array &$matches [, int $flags = 0 [, int $offset = 0 ]]] )
http://www.regexr.com/
http://php.net/manual/en/function.preg-match.php
 

No comments:

Post a Comment