Home  >  Article  >  Backend Development  >  A brief analysis of the specific usage of the PHP function ereg()_PHP Tutorial

A brief analysis of the specific usage of the PHP function ereg()_PHP Tutorial

WBOY
WBOYOriginal
2016-07-15 13:30:181220browse

In many high-level languages, Syntax: int ereg(string pattern, string string, array [regs]);

Return value: integer/array

Function type: Data processing

PHP function ereg() content description

This function uses pattern rules to parse and compare strings. The value returned by the comparison result is placed in the array parameter regs. The content of regs[0] is the original string, regs[1] is the first string that conforms to the rules, and regs[2] is the second string that conforms to the rules. string, and so on. If the parameter regs is omitted, it will simply be compared, and the return value will be true if found.

Usage example of PHP function ereg()

Simple example:

<ol class="dp-xml"><li class="alt"><span><span class="tag"><</span><span> ?php  </span></span></li><li><span>if (ereg("c","abcdef")){     <br />//说明:判断abcdef中是否含有字母c  </span></li><li class="alt"><span>     echo "通过";  </span></li><li><span>}else{  </span></li><li class="alt"><span>     echo "错误";  </span></li><li><span>}  </span></li><li class="alt"><span class="tag">?></span><span> </span></span></li></ol>

The following example of PHP function ereg() is for the input E -Mail performs a simple check to see if the user's E-Mail string contains the @ character. There are English letters or numbers before the @ character, followed by a string of several sections. There can only be two or three characters after the last decimal point. English letters. super@mail.wilson.gs can pass the check, but super@mail.wilson cannot pass the check.

<ol class="dp-xml"><li class="alt"><span><span class="tag"><</span><span> ?php  </span></span></li><li><span>if (ereg("^[_.0-9a-z-]+@([0-9a-z]<br />[0-9a-z-]+.)+[a-z]{2,3}$",$email))</span></li><li><span> {  </span></li><li class="alt"><span>   echo "您的 E-Mail 通过初步检查";  </span></li><li><span>}  </span></li><li class="alt"><span class="tag">?></span><span>   </span></span></li></ol>


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446312.htmlTechArticleIn many high-level languages, syntax: int ereg(string pattern, string string, array [regs]); Return Value: Integer/array Function type: Data processing PHP function ereg() Content Description This function starts with...
Statement:
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