Php uses the filter function to verify the mailbox, url, and IP address. In php programs, regular expressions are generally used to verify email addresses, IP addresses, and URLs. In fact, some built-in validation rules are provided in php. The following example describes how to use a php program to verify the mailbox, IP address, or url. generally, regular expressions are used for processing. In fact, php contains some built-in special verification rules. The following example describes how to use the built-in filter function of php to verify email, ip, and URL.
1. verify email
$ Email = 'phpernote @ 163.com '; $ result = filter_var ($ email, FILTER_VALIDATE_EMAIL); var_dump ($ result); // output: string (17) 'phpernote @ 163.com'
2. verify the url address
$ Url = 'http: // www.phpernote.com/'; $ result = filter_var ($ url, FILTER_VALIDATE_URL); var_dump ($ result); // output: string (25) 'http: // www.phpernote.com /'
3. verify the IP address
$ Url = '192. 168.0.1 '; $ result = filter_var ($ url, FILTER_VALIDATE_IP); var_dump ($ result); // output: string (11) '192. 168.0.1'
The filter function in php can also be used to verify floating-point numbers, integer numbers, and Boolean types. for details, refer to the filter function in the php manual or refer to the following article on this site:
PHP filter_var () function Filter function
Articles you may be interested in
- Common JS function Collection (remove spaces, verify email addresses, dates, positive integers, etc)
- PHP filter_var () function Filter function
- Php uses array_flip to implement array key-value exchange to remove array duplicate values
- Collect common php functions with explanations
- PHP string escape functions (addslashes, stripslashes)
- Php performance optimization: using isset () to determine the string length is faster than strlen ()
- Use the PHP function memory_get_usage to obtain the current PHP memory consumption for program performance optimization.
- URL encoding functions such as urlencode (), urldecode (), rawurlencode (), and rawurldecode ()
Bytes. The following example shows how to use it...