PHP Use Advanced Filters Examples
Hello,
As we speak, i we’ll present you PHP Use superior filters examples. This text gives you easy instance of PHP Use superior filters examples. you’ll be taught PHP Use superior filters examples.
I’ll present you this instance upfront filter perform in php Validate AN entire quantity amongst a range,Validate IPv6 Deal with,Validate common useful resource locator – ought to Comprise QueryString,Take away Characters With American Customary Code for Data Interchange value > 127 to defined.
So let’s comply with few step to create instance of PHP Use superior filters examples.
Validate an Integer Inside a Vary
This instance makes use of the filter_var() perform to look at if a variable is every of variety INT, and between 1 and two 200
<?php $int = 122; $min = 1; $max = 200; if (filter_var($int, FILTER_VALIDATE_INT, array("choices" => array("min_range"=>$min, "max_range"=>$max))) === false) { echo("Variable worth just isn't throughout the authorized vary"); } else { echo("Variable worth is throughout the authorized vary"); } ?>
Output:
Variable worth is throughout the authorized vary
Validate IPv6 Deal with
This instance makes use of the filter_var() perform to look at if the variable $ip may very well be a legitimate IPv6 deal with.
<?php $ip = "2001:0db8:85a3:08d3:1319:8a2e:0370:7334"; if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false) { echo("$ip is a legitimate IPv6 deal with"); } else { echo("$ip just isn't a legitimate IPv6 deal with"); } ?>
Output:
2001:0db8:85a3:08d3:1319:8a2e:0370:7334 is a legitimate IPv6 deal with
Validate URL – Should Comprise QueryString
This instance makes use of the filter_var() perform to look at if the variable $url is a URL with a querystring
<?php $url = "https://codeplaners.com"; if (!filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_QUERY_REQUIRED) === false) { echo("$url is a legitimate URL with a question string"); } else { echo("$url just isn't a legitimate URL with a question string"); } ?>
Output:
https://codeplaners.com just isn't a legitimate URL with a question string
Take away Characters With ASCII Worth > 127
This instance makes use of the filter_var() perform to sanitize a string. it’ll every take away all hypertext mark-up language tags, and each one characters with pc code value > 127, from the string
<?php $str = "<h1>Howdy WorldÆØÅ!</h1>"; $newstr = filter_var($str, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH); echo $newstr; ?>
Output:
Howdy World!
I hope it’s going to help you…
Komentar
Posting Komentar