xref: /php-src/ext/pcre/tests/001.phpt (revision f8d79582)
1--TEST--
2abusing preg_match()
3--FILE--
4<?php
5
6foreach (array('2006-05-13', '06-12-12', 'data: "12-Aug-87"') as $s) {
7    var_dump(preg_match('~
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', $s, $m));
13
14    var_dump($m);
15}
16
17?>
18--EXPECT--
19int(1)
20array(10) {
21  [0]=>
22  string(10) "2006-05-13"
23  ["date"]=>
24  string(10) "2006-05-13"
25  [1]=>
26  string(10) "2006-05-13"
27  ["year"]=>
28  string(4) "2006"
29  [2]=>
30  string(4) "2006"
31  [3]=>
32  string(2) "20"
33  ["month"]=>
34  string(2) "05"
35  [4]=>
36  string(2) "05"
37  ["day"]=>
38  string(2) "13"
39  [5]=>
40  string(2) "13"
41}
42int(1)
43array(10) {
44  [0]=>
45  string(8) "06-12-12"
46  ["date"]=>
47  string(8) "06-12-12"
48  [1]=>
49  string(8) "06-12-12"
50  ["year"]=>
51  string(2) "06"
52  [2]=>
53  string(2) "06"
54  [3]=>
55  string(0) ""
56  ["month"]=>
57  string(2) "12"
58  [4]=>
59  string(2) "12"
60  ["day"]=>
61  string(2) "12"
62  [5]=>
63  string(2) "12"
64}
65int(1)
66array(10) {
67  [0]=>
68  string(8) "12-Aug-8"
69  ["date"]=>
70  string(8) "12-Aug-8"
71  [1]=>
72  string(8) "12-Aug-8"
73  ["year"]=>
74  string(2) "12"
75  [2]=>
76  string(2) "12"
77  [3]=>
78  string(0) ""
79  ["month"]=>
80  string(3) "Aug"
81  [4]=>
82  string(3) "Aug"
83  ["day"]=>
84  string(1) "8"
85  [5]=>
86  string(1) "8"
87}
88