


Implementation and detailed explanation of regular expression of email address in PHP_PHP tutorial
First attach the code
^[_.0-9a-z-]+@( [0-9a-z][0-9a-z-]+.)+[a-z]{2,3}$
In this regular expression, "+" means the preceding One or more strings appear continuously; "^" means that the next string must appear at the beginning, "$" means that the previous string must appear at the end;
"." is also ".", here " " is an escape character; "{2,3}" means that the previous string can appear 2-3 times in a row. "()" indicates that the contained content must also appear in the target object. "[_.0-9a-z-]" means any character contained in "_", ".", "-", letters in the range from a to z, and numbers in the range from 0 to 9;
In this way, this regular expression can be translated like this:
"The following characters must be at the beginning (^)", "The characters must be contained in "_", ".", "-", from a to Letters in the z range, numbers in the range 0 to 9 ([_.0-9a-z-])", "The preceding character appears at least once (+)", @, "The string consists of Begins with a letter in the range a to z, a number in the range 0 to 9, followed by at least one character contained in "-", any letter in the range a to z, in the range 0 to 9 Any character in a number ends with . (([0-9a-z][0-9a-z-]+.))", "The previous character appears at least once (+)", "From a to Letters in the z range appear 2-3 times and end with it ([a-z]{2,3}$)"
function is_valid_email($email, $test_mx = false)
{
if(eregi("^([_a-z0-9-]+)(.[_a-z0 -9-]+)*@([a-z0-9-]+)(.[a-z0-9-]+)*(.[a-z]{2,4})[ wind_phpcode_0 ]quot;, $ email))
if($test_mx)
{
list($username, $domain) = split("@", $email);
return getmxrr($domain, $mxrecords);
}
else
return true;
else
return false;
}
The domain name consists of the specific character set, English letters, and numbers of each country's script and "-" (i.e. hyphen or minus sign), but cannot contain "-" at the beginning or end, and "-" cannot appear consecutively in the domain name. The domain name can have up to 60 characters. Bytes (including suffixes .com, .net, .org, etc.)
/^[a-z]([a-z0-9]*[-_]?[a-z0-9]+)*@( [a-z0-9]*[-_]?[a-z0-9]+)+[.][a-z]{2,3}([.][a-z]{2})?$/i;
/content/i constitutes a case-insensitive regular expression;
^ Match start
$ Match end
[a-z] E-Mail prefix must be an English Letters starting with
([a-z0-9]*[-_]?[a-z0-9]+)* match _a_2, aaa11, _1_a_2, but do not match a1_, aaff_33a_, a__aa, If it is a null character, it is also matched, and * means 0 or more.
* represents 0 or more previous characters.
[a-z0-9]* matches 0 or more English letters or numbers
[-_ ]? Matches 0 or 1 "-", because "-" cannot appear continuously
[a-z0-9]+ Matches 1 or more English letters or numbers, because "-" cannot be used as The ending
@ must have @
([a-z0-9]*[-_]?[a-z0-9]+)+ see above ([a-z0 -9]*[-_]?[a-z0-9]+)* explanation, but it cannot be empty, + means one or more.
[.] Treat special characters (.) as ordinary characters
[a-z]{2,3} matches 2 to 3 English letters, usually com or net, etc.
([.][a-z]{2})? Matches 0 or 1 [.][a-z]{2} (such as .cn, etc.) I don’t know if the last part of .com.cn is generally They are all two digits. If not, please modify {2} to {number of starting words, number of ending words}
Perfect E-Mail regular expression, with detailed explanation, please help test it! 2. Extract the email in the string:
function getEmail ($str) {
$pattern = "/([a-z0-9]*[-_.]?[a-z0-9]+)*@([a-z0-9]*[- _]?[a-z0-9]+)+[.][a-z]{2,3}([.][a-z]{2})?/i";
preg_match_all($pattern,$str . hh@qq.com;.;;,fuyongjie.100@yahoo.com,fu-1999@sina.com";
$emailArr = getEmail($emailstr);
echo "
"; <br>print_r($emailArr); <br>echo "";
?>Print as follows:
Array
(
[0] =>9999@qq .com.cn
[1] =>fuyongjie@163.com
[2] =>hh@qq.com
[3] =>fuyongjie.100@yahoo.com
[4] =>fu-1999@sina.com
) 3. Comparison: The ^ and $ in the 1st are not included in the regular expression in the 2nd;
Look at the example
Copy code
function funcemail($str)//Mailbox regular expression
{
return (preg_match('/^[_.0-9a-z-a-z-]+@([0-9a- z][0-9a-z-]+.)+[a-z]{2,4}$/',$str))?true:false;
}//Verification method one
$str= "qbcd@126.com.cn";
preg_match("/^[0-9a-z]+@(([0-9a-z]+)[.])+[a-z]{2,3 }$/",$str,$re);
print_r($re);//Email verification 2
if (eregi("^[_.0-9a-z-]+@([0 -9a-z][0-9a-z-]+.)+[a-z]{2,3}$",$email)) {
echo "Your email passed the preliminary check";
}//The third email verification method
if (ereg("/^[a-z]([a-z0-9]*[-_.]?[a-z0-9]+) *@([a-z0-9]*[-_]?[a-z0-9]+)+[.][a-z]{2,3}([.][a-z]{2})?$ /i; ",$email)){
echo "your email address is correct!";}
else{
echo "please try again!";
}

TooptimizePHPcodeforreducedmemoryusageandexecutiontime,followthesesteps:1)Usereferencesinsteadofcopyinglargedatastructurestoreducememoryconsumption.2)LeveragePHP'sbuilt-infunctionslikearray_mapforfasterexecution.3)Implementcachingmechanisms,suchasAPC

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

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

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.

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

Dreamweaver CS6
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download
The most popular open source editor
