Review of regular expressions in PHP (1)-php Tutorial

Source: Internet
Author: User
Review regular expressions in PHP (1) first review common regular expression functions in php.

1. preg_match () and preg_match_all ()

Int prag_match ($ pattern, $ subject, optional parameter $ matchs); only one match is performed, and the return value is 0 or 1, that is, the number of matching times, put the matched value into the third parameter, which is an array.

Int preg_match_all ($ pattern, $ subject, optional parameter $ matchs); to perform all matching, the returned value is also the number of matching times, put the matching value to the third parameter, is a two-digit array.

2. preg_replace () and preg_filter ()

Preg_replace ($ pattern regular, $ replacement content to be replaced with, $ subject target content); all three parameters can be arrays

Preg_filter (same as above); same as above

One difference between the two functions is that, when an array is used for matching, the returned value is preg_filter (), which returns only the replaced value, and the preg_replace () returns no matter whether it is replaced or not.

Preg_grep (); returns the matched value without replacement. This is equivalent to a function reduction version of preg_filter.

3. preg_split ($ pattern, $ subject );

Needless to say, an upgraded version of The explode () function.

4. preg_quote ($ str );

You can wake up and escape the regular expression operators in a string.

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.