当前位置:网站首页>Filters in PHP
Filters in PHP
2022-06-13 03:14:00 【wks19891215】
Checking strings is the most common function in programs . For example, meeting such a scene , Verify that the string matches ip Address format . There are usually two ways :
(1) Writing a ip Address verification function
(2) Regular expressions
In the use of C When language deals with such problems , It usually takes more than ten minutes to write a verification function . Using a language that supports regularity (php、C++11 etc. ) When dealing with such problems , Regular . But regularization is difficult to use , And it's not intuitive to read .( This in no way means that regularity is not important ). Sometimes they just want to quickly solve the immediate problems , So what should we do ? At least in the php We can use filters in .
The filter is used through the filter function , Such as filter_var Used to judge whether a variable meets the requirements
Here is a paragraph to verify IP And whether the email is valid :
<?php
$ip="192.168.0.222";
$is_ip=filter_var($ip,FILTER_VALIDATE_IP);
var_dump($is_ip);
$mail="[email protected]";
$is_mail=filter_var($mail,FILTER_VALIDATE_EMAIL);
var_dump($is_mail);
?>This is better than checking the string yourself or Regularization is much more convenient ~
php There are three types of filters in : with VALIDATE The typeface filter only checks if the string is valid , Does not change the state of the string . with SANITIZE The filter of will delete the sub strings that do not meet the requirements , The third is FILTER_CALLBACK. That is, use your own callback function for verification .
stay w3cschool There is an on-line website of form , A detailed list of php Functions of filters and filter functions in .
PS: Filter in PHP5.2 Later versions default to , Previous versions need to install extensions to use . The filter is easy to use , But its function is still limited , In the face of specific needs , And string Library 、 Regular combination .
边栏推荐
- Stack information, GC statistics
- Flutter reports an error type 'Int' is not a subtype of type 'string' wonderful experience
- Spark UDF instance details
- 关于复合函数的极限问题
- English语法_频率副词
- [JVM Series 2] runtime data area
- Available types in C #_ Unavailable type_ C double question mark_ C question mark point_ C null is not equal to
- Install MySQL database
- Wechat applet obtains the current location (startlocationupdate, onlocationchange, offlocationchange)
- Linked list: the entry node of the link in the linked list
猜你喜欢

Prometheus install and register services

MySQL 8.0 installation free configuration method

Wechat applet switch style rewriting
![HEAP[xxx.exe]: Invalid address specified to RtlValidateHeap( 0xxxxxx, 0x000xx)](/img/c9/884aa008a185a471dfe252c0756fc1.png)
HEAP[xxx.exe]: Invalid address specified to RtlValidateHeap( 0xxxxxx, 0x000xx)
![[JVM Series 2] runtime data area](/img/6c/82cc0ff9e14507f57492ed3f67a7f6.jpg)
[JVM Series 2] runtime data area

Mvcc and bufferpool (VI)

MySQL transactions and locks (V)

技术博客,经验分享宝典

Summary of the latest IOS interview questions in June 2020 (answers)

Wechat applet coordinate location interface usage (II) map interface
随机推荐
Open source - campus forum and resource sharing applet
Supervisor -- Process Manager
When the flutter runs the project, the gradle download fails, and the running gradle task 'assemblydebug' is always displayed
开源-校园论坛和资源共享小程序
C # simple understanding - method overloading and rewriting
Hash table: whether alien languages are sorted
Entity framework extends the actual combat, small project reconfiguration, no trouble
Radium laser radar C16 data to PCD (based on ROS)
Operating principle of JS core EventLoop
Linked list: the entry node of the link in the linked list
MySQL index bottom layer (I)
Linked list: reverse linked list
MySQL create user authorization remote access
Redis server configuration
English语法_方式副词-位置
Understanding of intermediatelayergetter
String: number of substring palindromes
. New features in net 6.0 _ What's new in net 6.0
PK of dotnet architecture
Unified scheduling and management of dataX tasks through web ETL