PHP Regular Expression Function Learning Summary _php Tutorial

Source: Internet
Author: User
Tags ereg php regular expression posix vars
What are the PHP regular expression functions? So what exactly does the PHP regular expression function represent? What is the specific usage? Let us introduce to you. PHP regular expressions are primarily used for the processing of 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 the regular expression matching function, the former is case-sensitive, the latter is irrelevant.

Usage:

Ereg (regular expression, string, [match partial array name]); Regular expressions in PHP3.0 are broadly similar to those used in grep.

(2) Ereg_replace,eregi_replace

These are replacement functions.

Usage:

Ereg_replace (Regular expression, substitution string, original string);

There is a strtr in the string handler function, which is a "translation" function, similar to the tr/.../.../in Perl,

Usage:

STRTR (String, "from", "to");

For example:

STRTR ("Aaabb", "AB", "CD") returns "CCCDD".

(3) Split

Similar to the EXPLODE function, but this time it is possible to split a string where it matches a regular expression.

Usage:

Split (regular expression, string, [how many items before removal]);

These functions use a regular string as the first argument. PHP uses the extended regular string defined by the POSIX 1003.2 standard. To see the full description of POSIX regular expressions see the man page under the Regex directory in the PHP package.

PHP Regular Expression Function application example:

 
 
  1. Ereg ("abc",$string);
  2. / * Returns true if "abc" is
  3. found anywhere in $string. * *
  4. Ereg ("^abc",$string);
  5. / * Returns true if "abc" is
  6. found at the beginning of $string. * *
  7. Ereg ("abc$",$string);
  8. / * Returns true if "abc" is
  9. found at the end of $string. * *
  10. Eregi ("(ozilla.[ 23]| MSIE.3) ",$HTTP _user_agent);
  11. / * Returns True if client browser
  12. is Netscape 2, 3 or MSIE 3. * /
  13. Ereg ([[: alnum:]]+) ([alnum:]]+)
  14. ([[: alnum:]]+) ", $string , $regs );
  15. / * Places Three space separated words
  16. Into $regs [1], $regs [2] and $regs [3]. * /
  17. ereg_replace ("^","",$string);
  18. / * Put a tag at the beginning of $string. * /
  19. ereg_replace ("$","",$string);
  20. / * Put a tag at the end of $string. * /
  21. ereg_replace ("","",$string);
  22. / * Get rid of any carriage
  23. return characters in $string. * /

The relevant contents of the PHP Regular expression function are introduced to you, and hopefully it will help you understand and learn about the PHP regular expression functions.


http://www.bkjia.com/PHPjc/446590.html www.bkjia.com true http://www.bkjia.com/PHPjc/446590.html techarticle What are the PHP regular expression functions? So what exactly does the PHP regular expression function represent? What is the specific usage? Let us introduce to you. PHP Regular Expressions ...

  • 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.