Home Backend Development PHP Tutorial PHP uses filter filter to verify email address ipv6 address url verification_PHP tutorial

PHP uses filter filter to verify email address ipv6 address url verification_PHP tutorial

Jul 13, 2016 pm 05:18 PM
email filter ipv6 php url code use address copy filter Mail verify

1. Verify email

Copy code The code is as follows:

$email = 'jb51@qq.com';
$result = filter_var ($email, FILTER_VALIDATE_EMAIL);
var_dump($result); //string(14) "jb51@qq.com"

2. Verify url address

Copy code The code is as follows:

$url = "http://www.jb51.net";
$result = filter_var($url, FILTER_VALIDATE_URL);
var_dump($result); //string(22) "http://www.jb51.net"

3. Verify IP address

Copy code The code is as follows:

$url = "192.168.1.110";
$result = filter_var($ url, FILTER_VALIDATE_IP);
var_dump($result); //string(13) "192.168.1.110"

It’s worth mentioning that this method can also be used to verify ipv6.

Copy code The code is as follows:

$url = "2001:DB8:2de::e13";
$ result = filter_var($url, FILTER_VALIDATE_IP);
var_dump($result); //string(17) "2001:DB8:2de::e13"

4. Verify whether the value is an integer and within an integer interval

Copy code The code is as follows:

$i = '010';
$result = filter_var(
$i,
FILTER_VALIDATE_INT,
//Set the value range for verification
array(
'options' => array('min_range' => 1, 'max_range' => 100)
)
);
var_dump($result);//bool(false)

PHP variables are weakly typed. If no filter is used and the greater than or less symbol is used directly to judge, it will be true.

Copy code The code is as follows:

$i = '010';
$result = $i >= 1 && $i <= 100;
var_dump($result);//bool(true)

5. Verify floating point numbers

Copy code The code is as follows:

$float = 12.312;
$result = filter_var($float, FILTER_VALIDATE_FLOAT) ;
var_dump($result); //float(12.312)

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/621664.htmlTechArticle1. The verification email copy code is as follows: $email = 'jb51@qq.com'; $result = filter_var ($email, FILTER_VALIDATE_EMAIL); var_dump($result); //string(14) "jb51@qq.com" 2. Verify url...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Clair Obscur: Expedition 33 - How To Get Perfect Chroma Catalysts
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1677
14
PHP Tutorial
1278
29
C# Tutorial
1257
24
PHP performance optimization strategies. PHP performance optimization strategies. May 13, 2025 am 12:06 AM

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHP Performance Optimization Checklist: Improve Speed Now PHP Performance Optimization Checklist: Improve Speed Now May 12, 2025 am 12:07 AM

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

PHP Email Validation: Ensuring Emails Are Sent Correctly PHP Email Validation: Ensuring Emails Are Sent Correctly May 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

PHP Email: Step-by-Step Sending Guide PHP Email: Step-by-Step Sending Guide May 09, 2025 am 12:14 AM

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

PHP Dependency Injection: Improve Code Testability PHP Dependency Injection: Improve Code Testability May 12, 2025 am 12:03 AM

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

PHP Dependency Injection Container: A Quick Start PHP Dependency Injection Container: A Quick Start May 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Go: String Manipulation with the Standard 'strings' Package Go: String Manipulation with the Standard 'strings' Package May 09, 2025 am 12:07 AM

Go uses the "strings" package for string operations. 1) Use strings.Join function to splice strings. 2) Use the strings.Contains function to find substrings. 3) Use the strings.Replace function to replace strings. These functions are efficient and easy to use and are suitable for various string processing tasks.

Guide to Sending Emails with PHP & SMTP Guide to Sending Emails with PHP & SMTP May 09, 2025 am 12:06 AM

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

See all articles