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

 array("min_range"=>$min, "max_range"=>$max))) === false) { echo("变量值不在合法范围内"); } else { echo("变量值在合法范围内"); } ?>

Try it»

Detect IPv6 address

The following example uses the filter_var() function to detect whether a $ip variable is an IPv6 address:

Example


Try it»

Detect URL - must contain QUERY_STRING (query string)

The following example uses the filter_var() function to detect whether $url contains Query string:

Example


Try it »

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 from a string. It can also remove HTML tags:

Example

Hello WorldÆØÅ!"; $newstr = filter_var($str, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH); echo $newstr; ?>


Try it out»

PHP Filter Reference Manual

You can also view the specific application of filters by visiting the PHP Filter Reference Manual on this site.

The reference manual contains a brief description and usage examples of filter parameters!


Continuing Learning
||
array("min_range"=>$min, "max_range"=>$max))) === false) { echo("变量值不在合法范围内"); } else { echo("变量值在合法范围内"); } ?>
submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!