Introduction to common functions of regular expressions in PHP

Source: Internet
Author: User
    1. Preg_match_all ("|<[^>]+> (. *) ]+>| U "," a Test ", $out, Preg_pattern_order);
    2. Print $out [0][0]. ",". $out [0][1]. " n ";
    3. Print $out [1][0]. ",". $out [1][1]. " N
    4. ?>
Copy Code

3,preg_replace parse and replace the string comparison.

Syntax: Mixed preg_replace (mixed pattern, mixed replacement, mixed subject);

Return value: Mixed type data

Function type: Data processing

Description: This function parses the subject string with the rule of pattern, and the string to be replaced is the parameter replacement. The return value is a mixed-type data, which is substituted for the string result.

Using the example, the following example returns a value of $startDate = 6/19/1969.

    1. $patterns = Array ("/(19|20d{2})-(d{1,2})-(d{1,2})/", "/^s*{(w+)}s*=/");
    2. $replace = Array ("3/4/1", "$ =");
    3. Print Preg_replace ($patterns, $replace, "{startdate} = 1969-6-19");
    4. ?>
Copy Code

4,preg_split the string according to the specified rule.

Syntax: Array preg_split (string pattern, string subject, int [limit]);

return value: Array

Function type: Data processing

Description: This function separates strings according to the specified rules. The return value after the cut is an array variable. The parameter pattern is the specified rule string, the parameter subject is the string to be processed, and the parameter limit can be omitted, indicating the maximum value to be processed.

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