PHP Methods for validating mailboxes, URLs, and IP addresses using the filter function _php Tutorial

Source: Internet
Author: User
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 ...

  • 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.