The previous use of PHP to verify that the mailbox, URL, IP is legitimate through their own write regular to achieve, but sometimes the brain faint, may write a not exactly the correct regular, leading to validation errors, today found that PHP itself with the verification mailbox, URL, IP is legitimate function.
The main use is the Filter_var function.
Grammar
filter_var(variable, filter, options)
Parameter description
Variable required. Specifies the variables to filter.
Filter is optional. Specifies the ID of the filter to be used.
The options rule contains an array of flags/options. Check the possible flags and options for each filter.
PHP Filters
ID name |
Description |
Filter_callback |
Invokes a user-defined function to filter the data. |
Filter_sanitize_string |
Remove tags, remove or encode special characters. |
filter_sanitize_stripped |
The alias of the "string" filter. |
filter_sanitize_encoded |
Url-encode string that removes or encodes special characters. |
Filter_sanitize_special_chars |
The HTML escape character ' "<>& and the ASCII value less than 32 characters. |
Filter_sanitize_email |
Remove all characters except letters, numbers, and!#$%& ' *+-/=?^_ ' {|} [Email protected] [] |
Filter_sanitize_url |
Delete all characters except letters, numbers, and $-_.+!* ' (), {}|\\^~[] ' <>#% ';/?:@&= |
Filter_sanitize_number_int |
Remove all characters except numbers and +- |
Filter_sanitize_number_float |
Remove all characters except numbers, +-and., EE. |
Filter_sanitize_magic_quotes |
Apply Addslashes (). |
Filter_unsafe_raw |
Do not filter, remove or encode special characters. |
Filter_validate_int |
Validates the value with an integer in the specified range. |
Filter_validate_boolean |
Returns true if "1″", "true", "on" and "Yes", and returns False if "0″," "false", "off", "No", and "". Otherwise, NULL is returned. |
Filter_validate_float |
Validates the value with a floating-point number. |
Filter_validate_regexp |
Based on RegExp, Perl-compatible regular expressions are validated for values. |
Filter_validate_url |
Verify the value as a URL. |
Filter_validate_email |
Verify the value as an e-mail. |
Filter_validate_ip |
Verify the value as an IP address. |
Example #1 A Filter_var () Example
?
1234 |
<?php var_dump(filter_var( ‘[email protected]‘ , FILTER_VALIDATE_EMAIL)); var_dump(filter_var( ‘http://example.com‘ , FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED)); ?> |
The above routines will output:
?
12 |
string(15) "[email protected]" bool(false) |
The above is a small series to introduce you to the PHP self-contained method to verify the mailbox, URL, IP is legitimate function, I hope that we have some help, if you have any questions please give me a message, small series will promptly reply to you. Thank you very much for the support of the Scripting House website!
Original link: http://blog.csdn.net/veloi/article/details/53520995
PHP comes with verification mailbox URL IP function