PHP advanced filter
Detect whether a number is within a range
The following example uses the filter_var() function to detect whether an INT type variable is within 1 to 200 :
Example
<?php
$int = 122;
$min = 1;
$max = 200;
if (filter_var($int, FILTER_VALIDATE_INT, array("options" => array("min_range"=>$min, "max_range"=>$max))) === false) {
echo("变量值不在合法范围内");
} else {
echo("变量值在合法范围内");
}
?>##Detect IPv6 address
The following example uses the filter_var() function to detect whether a $ip variable is an IPv6 address:Example<?php
$ip = "2001:0db8:85a3:08d3:1319:8a2e:0370:7334";
if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false) {
echo("$ip 是一个 IPv6 地址");
} else {
echo("$ip 不是一个 IPv6 地址");
}
?>Detect URL - must contain QUERY_STRING (query string)
The following example uses the filter_var() function to detect whether $url contains the query string: Example<?php
$url = "//m.sbmmt.com";
if (!filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_QUERY_REQUIRED) === false) {
echo("$url 是一个合法的 URL");
} else {
echo("$url 不是一个合法的 URL");
}
?>Remove characters with ASCII values greater than 127
The following example uses filter_var () function to remove characters with an ASCII value greater than 127 in a string. It can also remove HTML tags: Example<?php $str = "<h1>Hello WorldÆØÅ!</h1>"; $newstr = filter_var($str, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH); echo $newstr; ?>
new file
<?php
$ip = "2001:0db8:85a3:08d3:1319:8a2e:0370:7334";
if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false) {
echo("$ip 是一个 IPv6 地址");
} else {
echo("$ip 不是一个 IPv6 地址");
}
?>
Preview
Clear
- Course Recommendations
- Courseware download
The courseware is not available for download at the moment. The staff is currently organizing it. Please pay more attention to this course in the future~
Students who have watched this course are also learning
Let's briefly talk about starting a business in PHP
Quick introduction to web front-end development
Large-scale practical Tianlongbabu development of Mini version MVC framework imitating the encyclopedia website of embarrassing things
Getting Started with PHP Practical Development: PHP Quick Creation [Small Business Forum]
Login verification and classic message board
Computer network knowledge collection
Quick Start Node.JS Full Version
The front-end course that understands you best: HTML5/CSS3/ES6/NPM/Vue/...[Original]
Write your own PHP MVC framework (40 chapters in depth/big details/must read for newbies to advance)
















