Ereg ()
Parsing of string alignment.
Syntax: int Ereg (string pattern, string string, array [regs]);
return value: Integer/array
Function type: Data processing
This function parses string strings with the rule of pattern. The value returned from the result is placed in the array parameter regs, Regs[0] content is the original string, string, Regs[1] is the first rule of the string, Regs[2] is the second rule of the string, and so on. If the parameter regs is omitted, it is simply a comparison, and the return value is true if found.
Usage examples Simple example: |
<?php
if (Ereg ("C", "abcdef")) {//Description: Determine if the abcdef contains the letter C
echo "Pass";
}else{
echo "Error";
}
?>
The following example is a simple check of the input e-mail, check whether the user's e-mail string has the @ character, before the @ character has an English letter or number, after a few strings, the last decimal point can only have two or three English letters. [email protected] can be checked, [email protected] cannot pass the check.
<?php
if (Ereg ("^[_/.0-9a-z-][email protected") ([0-9a-z][0-9a-z-]+/.) +[a-z]{2,3}$ ", $email)) {
echo "Your e-mail through a preliminary check";
}
?>
Eregi ()
Usage is the same as Ereg (). The difference is that
The following examples illustrate the differences between the two functions:
Find in abcdef Whether it contains capital letters c
<?php
if (Ereg ("C", "abcdef")) {
echo "Pass";
}else{
echo "Error";
}
?>
Returns the result: Error
<?php
if (eregi ("C", "abcdef")) {
echo "Pass";
}else{
echo "Error";
}
?>
The return result is: by
Ereg () is case-sensitive, eregi () This function is not related to casing.
Example
<?php $str = "a"; if (Eregi ("[0-9]+", $str)) { echo "This is a number"; } else if (eregi ("[a-z]+", $str)) { echo "This is a letter"; } else if (eregi ("[one-Calls]+", $str)) { echo "This is a Chinese character"; } ?> |
Go PHP ereg () differs from eregi () and the same point. Contrast