1--TEST--
2Test preg_match_all() function : basic functionality
3--FILE--
4<?php
5/*
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
8*/
9$string = 'Hello, world! This is a test. This is another test. \[4]. 34534 string.';
10var_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)
11var_dump($match1);
12var_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)
13var_dump($match2);
14var_dump(preg_match_all('@\. \\\(.*).@', $string, $match3, PREG_PATTERN_ORDER)); //finds ".\ [...]" and everything else to the end of the string. (greedy) (1 match)
15var_dump($match3);
16var_dump(preg_match_all('/\d{2}$/', $string, $match4)); //tries to find 2 digits at the end of a string (0 matches)
17var_dump($match4);
18var_dump(preg_match_all('/(This is a ){2}(.*)\stest/', $string, $match5)); //tries to find "This is aThis is a [...] test" (0 matches)
19var_dump($match5);
20
21// Test not passing in a subpatterns array.
22var_dump(preg_match_all('/test/', $string));
23var_dump(preg_match_all('/this isn\'t in the string/', $string));
24var_dump(preg_match_all('/world/', $string));
25var_dump(preg_match_all('/[0-9]/', $string));
26?>
27--EXPECT--
28int(1)
29array(1) {
30  [0]=>
31  array(1) {
32    [0]=>
33    array(2) {
34      [0]=>
35      string(1) "3"
36      [1]=>
37      int(61)
38    }
39  }
40}
41int(2)
42array(2) {
43  [0]=>
44  array(2) {
45    [0]=>
46    string(15) "This is a test."
47    [1]=>
48    string(5) " test"
49  }
50  [1]=>
51  array(2) {
52    [0]=>
53    string(21) "This is another test."
54    [1]=>
55    string(11) "nother test"
56  }
57}
58int(1)
59array(2) {
60  [0]=>
61  array(1) {
62    [0]=>
63    string(21) ". \[4]. 34534 string."
64  }
65  [1]=>
66  array(1) {
67    [0]=>
68    string(17) "[4]. 34534 string"
69  }
70}
71int(0)
72array(1) {
73  [0]=>
74  array(0) {
75  }
76}
77int(0)
78array(3) {
79  [0]=>
80  array(0) {
81  }
82  [1]=>
83  array(0) {
84  }
85  [2]=>
86  array(0) {
87  }
88}
89int(2)
90int(0)
91int(1)
92int(6)
93