PHP program to verify the mailbox, IP address or URL in general, we will use regular expressions to deal with, in fact, in PHP there are some built-in special validation rules. Here's an example of how to use the PHP built-in filter function to verify EMAIL,IP and URLs.
1, verify the mailbox
$email = ' phpernote@163.com '; $result =filter_var ($email, Filter_validate_email); Var_dump ($result);//output: string (+) ' 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 (+) ' http://www.phpernote.com/'
3. Verify 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 the floating-point number, shaped numbers, Boolean types, etc., can be consulted in the PHP manual filter function or reference to the site as follows this article
PHP Filter_var () function Filter function
Articles you may be interested in
- JS Common function Collection (remove space, verify mailbox, date, positive integer, etc.)
- PHP Filter_var () function Filter function
- PHP uses Array_flip to implement array key-value Exchange to remove array duplicate values
- PHP common functions are collected and accompanied by explanatory notes
- PHP string Escape function (Addslashes,stripslashes) detailed
- PHP Performance Optimizations: Use Isset () to determine string length faster than strlen ()
- Use PHP function memory_get_usage to get the current PHP memory consumption to achieve program performance optimization
- PHP addresses URL encoding problem functions UrlEncode (), UrlDecode (), Rawurlencode (), Rawurldecode ()
http://www.bkjia.com/PHPjc/764086.html www.bkjia.com true http://www.bkjia.com/PHPjc/764086.html techarticle PHP Program to verify the mailbox, IP address or URL in general, we will use regular expressions to deal with, in fact, in PHP there are some built-in special validation rules. Here's an example of how to use ...