xref: /PHP-7.4/ext/pcre/tests/marks.phpt (revision e03739d4)
1--TEST--
2Test support for PCRE marks
3--FILE--
4<?php
5
6$regex = <<<'REGEX'
7/
8    _ (a) (*MARK:A_MARK) _
9  | _ (b) _
10  | _ (c) (*MARK:C_MARK) _
11  | _ (d) _
12/x
13REGEX;
14
15var_dump(preg_match($regex, '_c_', $matches));
16var_dump($matches);
17
18var_dump(preg_match_all($regex, '_a__b__c__d_', $matches, PREG_PATTERN_ORDER));
19var_dump($matches);
20
21var_dump(preg_match_all($regex, '_a__b__c__d_', $matches, PREG_SET_ORDER));
22var_dump($matches);
23
24var_dump(preg_replace_callback($regex, function($matches) {
25    var_dump($matches);
26    return $matches[0];
27}, '_a__b__c__d_'));
28
29?>
30--EXPECT--
31int(1)
32array(5) {
33  [0]=>
34  string(3) "_c_"
35  [1]=>
36  string(0) ""
37  [2]=>
38  string(0) ""
39  [3]=>
40  string(1) "c"
41  ["MARK"]=>
42  string(6) "C_MARK"
43}
44int(4)
45array(6) {
46  [0]=>
47  array(4) {
48    [0]=>
49    string(3) "_a_"
50    [1]=>
51    string(3) "_b_"
52    [2]=>
53    string(3) "_c_"
54    [3]=>
55    string(3) "_d_"
56  }
57  [1]=>
58  array(4) {
59    [0]=>
60    string(1) "a"
61    [1]=>
62    string(0) ""
63    [2]=>
64    string(0) ""
65    [3]=>
66    string(0) ""
67  }
68  [2]=>
69  array(4) {
70    [0]=>
71    string(0) ""
72    [1]=>
73    string(1) "b"
74    [2]=>
75    string(0) ""
76    [3]=>
77    string(0) ""
78  }
79  [3]=>
80  array(4) {
81    [0]=>
82    string(0) ""
83    [1]=>
84    string(0) ""
85    [2]=>
86    string(1) "c"
87    [3]=>
88    string(0) ""
89  }
90  [4]=>
91  array(4) {
92    [0]=>
93    string(0) ""
94    [1]=>
95    string(0) ""
96    [2]=>
97    string(0) ""
98    [3]=>
99    string(1) "d"
100  }
101  ["MARK"]=>
102  array(2) {
103    [0]=>
104    string(6) "A_MARK"
105    [2]=>
106    string(6) "C_MARK"
107  }
108}
109int(4)
110array(4) {
111  [0]=>
112  array(3) {
113    [0]=>
114    string(3) "_a_"
115    [1]=>
116    string(1) "a"
117    ["MARK"]=>
118    string(6) "A_MARK"
119  }
120  [1]=>
121  array(3) {
122    [0]=>
123    string(3) "_b_"
124    [1]=>
125    string(0) ""
126    [2]=>
127    string(1) "b"
128  }
129  [2]=>
130  array(5) {
131    [0]=>
132    string(3) "_c_"
133    [1]=>
134    string(0) ""
135    [2]=>
136    string(0) ""
137    [3]=>
138    string(1) "c"
139    ["MARK"]=>
140    string(6) "C_MARK"
141  }
142  [3]=>
143  array(5) {
144    [0]=>
145    string(3) "_d_"
146    [1]=>
147    string(0) ""
148    [2]=>
149    string(0) ""
150    [3]=>
151    string(0) ""
152    [4]=>
153    string(1) "d"
154  }
155}
156array(3) {
157  [0]=>
158  string(3) "_a_"
159  [1]=>
160  string(1) "a"
161  ["MARK"]=>
162  string(6) "A_MARK"
163}
164array(3) {
165  [0]=>
166  string(3) "_b_"
167  [1]=>
168  string(0) ""
169  [2]=>
170  string(1) "b"
171}
172array(5) {
173  [0]=>
174  string(3) "_c_"
175  [1]=>
176  string(0) ""
177  [2]=>
178  string(0) ""
179  [3]=>
180  string(1) "c"
181  ["MARK"]=>
182  string(6) "C_MARK"
183}
184array(5) {
185  [0]=>
186  string(3) "_d_"
187  [1]=>
188  string(0) ""
189  [2]=>
190  string(0) ""
191  [3]=>
192  string(0) ""
193  [4]=>
194  string(1) "d"
195}
196string(12) "_a__b__c__d_"
197