xref: /PHP-5.6/ext/pcre/tests/003.phpt (revision 0df2a37d)
1--TEST--
2abusing preg_match_all()
3--FILE--
4<?php
5
6foreach (array(PREG_PATTERN_ORDER, PREG_SET_ORDER) as $flag) {
7	var_dump(preg_match_all('~
8		(?P<date>
9		(?P<year>(\d{2})?\d\d) -
10		(?P<month>(?:\d\d|[a-zA-Z]{2,3})) -
11		(?P<day>[0-3]?\d))
12		~x',
13		'2006-05-13 e outra data: "12-Aug-37"', $m, $flag));
14
15	var_dump($m);
16}
17?>
18--EXPECT--
19int(2)
20array(10) {
21  [0]=>
22  array(2) {
23    [0]=>
24    string(10) "2006-05-13"
25    [1]=>
26    string(9) "12-Aug-37"
27  }
28  ["date"]=>
29  array(2) {
30    [0]=>
31    string(10) "2006-05-13"
32    [1]=>
33    string(9) "12-Aug-37"
34  }
35  [1]=>
36  array(2) {
37    [0]=>
38    string(10) "2006-05-13"
39    [1]=>
40    string(9) "12-Aug-37"
41  }
42  ["year"]=>
43  array(2) {
44    [0]=>
45    string(4) "2006"
46    [1]=>
47    string(2) "12"
48  }
49  [2]=>
50  array(2) {
51    [0]=>
52    string(4) "2006"
53    [1]=>
54    string(2) "12"
55  }
56  [3]=>
57  array(2) {
58    [0]=>
59    string(2) "20"
60    [1]=>
61    string(0) ""
62  }
63  ["month"]=>
64  array(2) {
65    [0]=>
66    string(2) "05"
67    [1]=>
68    string(3) "Aug"
69  }
70  [4]=>
71  array(2) {
72    [0]=>
73    string(2) "05"
74    [1]=>
75    string(3) "Aug"
76  }
77  ["day"]=>
78  array(2) {
79    [0]=>
80    string(2) "13"
81    [1]=>
82    string(2) "37"
83  }
84  [5]=>
85  array(2) {
86    [0]=>
87    string(2) "13"
88    [1]=>
89    string(2) "37"
90  }
91}
92int(2)
93array(2) {
94  [0]=>
95  array(10) {
96    [0]=>
97    string(10) "2006-05-13"
98    ["date"]=>
99    string(10) "2006-05-13"
100    [1]=>
101    string(10) "2006-05-13"
102    ["year"]=>
103    string(4) "2006"
104    [2]=>
105    string(4) "2006"
106    [3]=>
107    string(2) "20"
108    ["month"]=>
109    string(2) "05"
110    [4]=>
111    string(2) "05"
112    ["day"]=>
113    string(2) "13"
114    [5]=>
115    string(2) "13"
116  }
117  [1]=>
118  array(10) {
119    [0]=>
120    string(9) "12-Aug-37"
121    ["date"]=>
122    string(9) "12-Aug-37"
123    [1]=>
124    string(9) "12-Aug-37"
125    ["year"]=>
126    string(2) "12"
127    [2]=>
128    string(2) "12"
129    [3]=>
130    string(0) ""
131    ["month"]=>
132    string(3) "Aug"
133    [4]=>
134    string(3) "Aug"
135    ["day"]=>
136    string(2) "37"
137    [5]=>
138    string(2) "37"
139  }
140}
141