How to use PHP to verify whether the email is qualified

autoload
Release: 2023-03-09 06:00:01
Original
1982 people have browsed it

How to use PHP to verify whether the email is qualified

本文主要利用的相关函数filter_var()trim()函数来判断邮箱是否正确。

1.相关函数的语法知识:

filter_var()语法格式:

filter_var ( mixed $value , int $filter = FILTER_DEFAULT , array|int $options = 0 ) : mixed
Copy after login
  • $value要过滤的变量。

  • $filter要使用的过滤器的 ID,本文是验证邮件的,所以使用的是FILTER_VALIDATE_EMAIL,ID 为274。

  • $options一个包含标志/选项的关联数组或者一个单一的标志/选项。

返回值:返回过滤后的数据,如果过滤失败则返回false

trim()语法格式:

trim ( string $str , string $character_mask = " \t\n\r\0\x0B" ) : string
Copy after login
  • $str待处理的字符串。

  • $character_mask为可选参数,默认值为“\t\n\r\0\x0B”,过滤字符也可由$character_mask参数指定。一般要列出所有希望过滤的字符,也可以使用 “..” 列出一个字符范围。

返回值:此函数返回字符串 str 去除首尾空白字符后的结果。如果不指定第二个参数,trim()将去除$character_mask的默认值。

2.使用的示例:


        
Copy after login

推荐:《php视频教程》《php教程

The above is the detailed content of How to use PHP to verify whether the email is qualified. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!