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