2 Test preg_match_all() function : basic functionality
6 * proto int preg_match_all(string pattern, string subject, [array subpatterns [, int flags [, int offset]]])
7 * Function is implemented in ext/pcre/php_pcre.c
9 $string = 'Hello, world! This is a test. This is another test. \[4]. 34534 string.';
10 var_dump(preg_match_all('/[0-35-9]/', $string, $match1, PREG_OFFSET_CAPTURE|PREG_PATTERN_ORDER, -10)); //finds any digit that's not 4 10 digits from the end(1 match)
12 var_dump(preg_match_all('/[tT]his is a(.*?)\./', $string, $match2, PREG_SET_ORDER)); //finds "This is a test." and "This is another test." (non-greedy) (2 matches)
14 var_dump(preg_match_all('@\. \\\(.*).@', $string, $match3, PREG_PATTERN_ORDER)); //finds ".\ [...]" and everything else to the end of the string. (greedy) (1 match)
16 var_dump(preg_match_all('/\d{2}$/', $string, $match4)); //tries to find 2 digits at the end of a string (0 matches)
18 var_dump(preg_match_all('/(This is a ){2}(.*)\stest/', $string, $match5)); //tries to find "This is aThis is a [...] test" (0 matches)
21 // Test not passing in a subpatterns array.
22 var_dump(preg_match_all('/test/', $string));
23 var_dump(preg_match_all('/this isn\'t in the string/', $string));
24 var_dump(preg_match_all('/world/', $string));
25 var_dump(preg_match_all('/[0-9]/', $string));
46 string(15) "This is a test."
53 string(21) "This is another test."
55 string(11) "nother test"
63 string(21) ". \[4]. 34534 string."
68 string(17) "[4]. 34534 string"