PHP Regular Expression functions

Source: Internet
Author: User
Tags ereg lowercase php regular expression

With regard to regular expressions (Regular Expression_r), it seems to be translated into: string parsing is more literal meaning. But at present all the related books are translated into regular expressions or formal representations .... And so on, is actually responsible for string resolution alignment, and for strings to do related processing.

Ereg: string alignment parsing.
Ereg_replace: The string is parsed and replaced.
Eregi: string alignment parsing, regardless of case.
Eregi_replace: String comparison resolution and substitution, regardless of case.
Split: Cuts the string according to a specified rule.
Sql_regcase: Returns uppercase and lowercase characters verbatim from a string. Ereg

string alignment parsing.

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

Return Value: Boolean value

Function type: Data processing

Content Description

This function resolves string strings using pattern rules. The value returned by the result is placed in the array parameter regs, Regs[0] content is the original string string, Regs[1] is the first regular string, regs[2] is the second rule string, and so on. If the argument regs is omitted, the return value is true only if it is simply compared.

Usage examples

This example is markus@dnet.it in 14-jun-1999, the user input of the e-mail can be a simple check, check whether the user's e-mail string has the @ character, in front of the @ character has English letters or numbers, after a few sections string, after the last decimal point Can only have two or three English letters. Super@mail.wilson.gs can pass the examination, Super@mail.wilson cannot pass the examination.

<?php
if (Eregi (^[_\.0-9a-z-]+@) ([0-9a-z][0-9a-z-]+\.) +[a-z]{2,3}$ ", $email)) {
echo "Your e-mail through preliminary check";
}
?>

ereg_replace

String pairs are parsed and replaced.

Syntax: string ereg_replace (string pattern, string replacement, string string);

return value: String

Function type: Data processing

Content Description

This function resolves the string string with the rule of pattern, and replacement the strings to be replaced by parameters. The return value is a string type, and the result of the string is replaced.

Usage examples

Ken@freebsdrocks.com The example presented in 16-mar-1999.

<?php
$text = ' is ' a {1} day, not {2} and {3}. '
$daytype = Array (1 => ' fine '),
2 => ' Overcast ',
3 => ' rainy ');
while (Ereg ([0-9]+)} ', $text, $regs)) {
$found = $regs [1];
$text = ereg_replace ("\{". $found. " \} ", $daytype [$found], $text);
}
echo "$text \ n";
This is a fine day, not overcast and rainy.
?>

Ken@freebsdrocks.com also provides examples of Perl programs with the same functionality as the following:

$text = ' is ' a {1} day, not {2} and {3}. '
%daytype = (1 => ' fine ',
2 => ' Overcast ',
3 => ' rainy ');
$text =~ s/{(\d+)}/$daytype {$1}/eg;
print "$text \ n";

The result is: ' It's a fine day, not overcast and rainy.

Eregi

String alignment parsing, regardless of case.

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

return value: Integer/array

Function type: Data processing

Content Description

This function is similar to Ereg () and uses the same. The difference is that ereg () is case-sensitive and this function has nothing to do with case. Eregi_replace

String pairs are parsed and superseded, regardless of case.

Syntax: string eregi_replace (string pattern, string replacement, string string);

return value: String

Function type: Data processing

Content Description

This function is similar to ereg_replace () and uses the same. The difference is that ereg_replace () is case-sensitive and this function has nothing to do with case.

Split

Cuts the string according to a specified rule.

Syntax: array Split (string pattern, string string, int [limit]);

return value: Array

Function type: Data processing

Content Description

This function separates strings according to the rules you specify. The returned value after the incision is an array variable. The parameter pattern is the specified rule string, the parameter string is the string to be processed, and the parameter limit can be omitted, indicating that the most desirable value is to be processed. It is noteworthy that the pattern parameters of this function are case-sensitive. Sql_regcase

Returns the string literal to uppercase and lowercase characters.

Syntax: string Sql_regcase (String string);

return value: Array

Function type: Data processing

Content Description

This function returns the character of a string verbatim to case. This function has no effect on PHP usage, but may provide external programs or database processing.

Usage examples

The return string in the example is [WW][II][LL][SS][OO][NN]

<?php
Print (Sql_regcase ("Wilson"));
?>

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.