PHP regular expression function learning summary. What about PHP regular expression functions? So what exactly does the PHP regular expression function mean? What is the specific usage? Let's introduce you one by one. What are PHP regular expression functions? So what exactly does the PHP regular expression function mean? What is the specific usage? Let's introduce you one by one. PHP regular expressions are mainly used to process complex strings. The main PHP regular expression functions are as follows:
◆ Ereg ()
◆ Ereg_replace ()
◆ Eregi ()
◆ Eregi_replace ()
◆ Split ()
PHP regular expression function usage induction:
(1) ereg, eregi
This is a regular expression matching function. The former is case-sensitive and the latter is irrelevant.
Usage:
Ereg (regular expression, string, [match part of the array name]); regular expression in PHP3.0 is generally similar to that in grep.
(2) ereg_replace, eregi_replace
These are replacement functions.
Usage:
Ereg_replace (regular expression, replacement string, original string );
The string processing function has a strtr, which is a "translation" function, similar to tr/.../in Perl /.../.../,
Usage:
Strtr (string, "from", "");
For example:
Strtr ("aaabb", "AB", "cd") returns "cccdd ".
(3) split
It is similar to The explode function, but this time it can be used to split the string where a regular expression is matched.
Usage:
Split (regular expression, string, [number of items before removal]);
These functions use regular strings as the first parameter. PHP uses the extended regular string defined by the Posix 1003.2 standard. For a complete description of Posix regular expressions, see the man page under the regex directory in the PHP software package.
PHP regular expression function application example:
- ereg("abc",$string);
- /* Returns true if "abc" is
- found anywhere in $string. */
-
- ereg("^abc",$string);
- /* Returns true if "abc" is
- found at the beginning of $string. */
-
- ereg("abc$",$string);
- /* Returns true if "abc" is
- found at the end of $string. */
-
- eregi("(ozilla.[23]|MSIE.3)",$HTTP_USER_AGENT);
- /* Returns true if client browser
- is Netscape 2, 3 or MSIE 3. */
-
- ereg("([[:alnum:]]+) ([[:alnum:]]+)
- ([[:alnum:]]+)",$string,$regs);
- /* Places three space separated words
- into $regs[1], $regs[2] and $regs[3]. */
-
- ereg_replace("^","",$string);
- /* Put a tag at the beginning of $string. */
-
- ereg_replace("$","",$string);
- /* Put a tag at the end of $string. */
-
- ereg_replace(" ","",$string);
- /* Get rid of any carriage
- return characters in $string. */
The related content of PHP regular expression functions will be introduced here, and it is helpful for you to understand and learn PHP regular expression functions.
Why? So what exactly does the PHP regular expression function mean? What is the specific usage? Let's introduce you one by one. PHP regular expression...