PHP Common string regular substitution and split function comparison _php tutorial

Source: Internet
Author: User
Tags php regular expression
This article is to introduce PHP common string regular substitution and split function comparison, in PHP string regular replacement is probably: Str_replace, Str_ireplace, Substr_replace, Preg_replace, Preg_match, Preg_match_all, Preg_quote, Preg_split, Ereg_replace, Eregi_replace, Preg_replace, str_split functions, let me introduce to you.

Regular function relationship ambiguous so all put together to compare, convenient reference.

Name Support Regular Characteristics Note
Str_replace X String substitution function, case sensitive
Str_ireplace X String substitution function, case insensitive, array-type batch substitution support Thank netizens Franci, remind to add
Substr_replace X Partial substitution string function, you can specify the position index
Preg_replace Y Specifying a matching pattern for substitution, supporting substring references Priority use
Ereg_replace Y Specify matching pattern for substitution, case sensitivity, support for substring references
Eregi_replace Y Specifies that the matching pattern is replaced, case insensitive, and supports substring references
Ereg Y Specifies the pattern full-text match, which can be used to match the judgment, or return a matching array
Preg_match Y Specifies whether the pattern matches one exit, which can be used to match the judgment, or to use the returned matching array Priority use
Preg_match_all Y Specifies a pattern full-text match, typically used to return a matching array Priority use
Preg_split Y Specifies the regular split in the matching mode, if it is best to use explode or str_split
Str_split X Specifies the length of the split string, by default a single character split into an array
Explode X You can specify a single or multiple character splitting string, and a successful return array, for example, 12345 returns 12 and 5 according to the 34 split
Preg_quote - Escape regular expression characters, meaning that special characters are prefixed with backslashes, and special characters for regular expressions include:. + * ? [ ^ ] $ ( ) { } = ! < > | : -

Additional notes:

1, there are two sets of regular expression function library in PHP, the function is very similar:

The set is provided by the POSIX (portable Operating System Interface of Unix) library, which is named after the Ereg_ prefix and isno longer recommended for POSIX regular libraries .

The set is provided by the Pcre (Perl Compatible Regular Expression) library, which is named after the Preg_ prefix and is recommended for priority use. In pcre, a pattern expression (that is, a regular expression) is typically included between two backslashes "/", such as the "/^w+$/" style.

2, PHP Regular expression function: matching extraction, matching replacement.


http://www.bkjia.com/PHPjc/445638.html www.bkjia.com true http://www.bkjia.com/PHPjc/445638.html techarticle this article to introduce PHP commonly used string regular substitution and split function comparison, in PHP string regular replacement is probably: Str_replace, Str_ireplace, Substr_replace, Preg_replace, PR ...

  • Related Article

    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.