Go PHP ereg () differs from eregi () and the same point. Contrast

Source: Internet
Author: User
Tags ereg

Ereg ()

Parsing of string alignment.

Syntax: int Ereg (string pattern, string string, array [regs]);

return value: Integer/array

Function type: Data processing

Content Description

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.