Home >Backend Development >PHP Tutorial >A brief analysis of the specific usage of the PHP function ereg()_PHP Tutorial
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>