Regular expression: PHP match, match_all

Source: Internet
Author: User
Tags preg
: This article mainly introduces the regular expression PHP match and match_all. if you are interested in the PHP Tutorial, refer to it.
  • Preg_match ($ pattern, $ subject, [array & match]) preg_match_all ($ pattern, $ subject, array & matches)
    Preg match only matches once. the returned value is 0 or 1;
    Preg match all matches multiple times and returns the number of times that match each time;
    $ Pattern regular expression;
    $ String or array to be matched by subject;
// Preg_match, preg_match_all $ pattern = '/[0-9]/'; $ subject = 'y1jp78yn16ww55 '; // define two empty arrays $ m1 = $ m2 = array (); $ t1 = preg_match ($ pattern, $ subject, $ m1 ); // $ m1 outputs a one-dimensional array. The return value is assigned to $ t1 $ t2 = preg_match_all ($ pattern, $ subject, $ m2 ); // $ m2 outputs a two-dimensional array. The return value is assigned to $ t2show ($ m1). // debug and output echo using the show function'
  '; Show ($ m2); echo'
  '; Show ($ t1.' | '. $ t2); // The number of matching times.

Preg_match can be matched at most once. the returned result is only 0 or the first matched element, in the form of an array.
Preg_match_all all match. The returned result may be 0 or all matched elements in the multi-dimensional array format.

'). AddClass ('pre-numbering '). hide (); $ (this ). addClass ('Has-numbering '). parent (). append ($ numbering); for (I = 1; I <= lines; I ++) {$ numbering. append ($ ('
  • '). Text (I) ;}; $ numbering. fadeIn (1700) ;}) ;}; script

    The above describes the regular expression PHP article match and match_all, including some content, hope to be helpful to friends who are interested in PHP tutorials.

    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.