PHP's own method to verify the mailbox, URL, IP is legitimate function _php skills

Source: Internet
Author: User
Tags encode string

Before using PHP to verify the mailbox, URL, IP is the legal is written by their own to achieve, but sometimes the brain is faint, may write a not completely correct regular, leading to validation errors, today found that the original PHP itself with the verification of mailboxes, URLs, IP is legitimate functions.

The main use is the Filter_var function.

Grammar

filter_var(variable, filter, options)

Parameter description

Variable required. Specify the variables to filter.

Filter can be selected. Specify the ID of the filter to use.

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 Call user-defined functions to filter 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 to remove or encode special characters.
Filter_sanitize_special_chars HTML escape character ' "<>& and ASCII value less than 32 characters.
Filter_sanitize_email Remove all characters except letters, numbers, and!#$%& ' *+-/=?^_ ' {|} ~@. []
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 No filtering, removal or encoding of special characters.
Filter_validate_int Validates a value in a specified range with an integer.
Filter_validate_boolean Returns true if "1″", "true", "on" and "Yes", or False if "0″", "false", "off", "No", and "". Otherwise NULL is returned.
Filter_validate_float Validates values with floating-point numbers.
Filter_validate_regexp According to RegExp, the Perl-compatible regular expression validates the value.
Filter_validate_url Validates 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

<?php
var_dump (Filter_var (' bob@example.com ', filter_validate_email));
Var_dump (Filter_var (' http://example.com ', Filter_validate_url, filter_flag_path_required));
? >

The above routines will output:

String "bob@example.com"
bool (FALSE)

The above is a small set of PHP to introduce a method to verify the mailbox, URL, IP is the legal function, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.