xref: /PHP-5.3/ext/ereg/tests/split_basic_001.phpt (revision 1881091e)
1--TEST--
2Test split() function : basic functionality - test a number of simple split, specifying a limit
3--FILE--
4<?php
5/* Prototype  : proto array split(string pattern, string string [, int limit])
6 * Description: Split string into array by regular expression
7 * Source code: ext/standard/reg.c
8 * Alias to functions:
9 */
10
11/*
12 * Test a number of simple split, specifying a limit
13 */
14
15echo "*** Testing ereg() : basic functionality ***\n";
16
17include(dirname(__FILE__) . '/regular_expressions.inc');
18
19foreach ($expressions as $re) {
20	list($pattern,$string) = $re;
21	echo "\n--> Pattern: '$pattern'; match: '$string'\n";
22	var_dump(split($pattern, $string . ' |1| ' . $string . ' |2| ' . $string, 2));
23}
24
25echo "Done";
26?>
27--EXPECTF--
28*** Testing ereg() : basic functionality ***
29
30--> Pattern: '..(a|b|c)(a|b|c)..'; match: '--- ab ---'
31
32Deprecated: Function split() is deprecated in %s on line %d
33array(2) {
34  [0]=>
35  string(2) "--"
36  [1]=>
37  string(32) "-- |1| --- ab --- |2| --- ab ---"
38}
39
40--> Pattern: '()'; match: ''
41
42Deprecated: Function split() is deprecated in %s on line %d
43
44Warning: split(): Invalid Regular Expression in %s on line %d
45bool(false)
46
47--> Pattern: '()'; match: 'abcdef'
48
49Deprecated: Function split() is deprecated in %s on line %d
50
51Warning: split(): Invalid Regular Expression in %s on line %d
52bool(false)
53
54--> Pattern: '[x]|[^x]'; match: 'abcdef'
55
56Deprecated: Function split() is deprecated in %s on line %d
57array(2) {
58  [0]=>
59  string(0) ""
60  [1]=>
61  string(27) "bcdef |1| abcdef |2| abcdef"
62}
63
64--> Pattern: '(a{1})(a{1,}) (b{1,3}) (c+) (d?ddd|e)'; match: '--- aaa bbb ccc ddd ---'
65
66Deprecated: Function split() is deprecated in %s on line %d
67array(2) {
68  [0]=>
69  string(4) "--- "
70  [1]=>
71  string(60) " --- |1| --- aaa bbb ccc ddd --- |2| --- aaa bbb ccc ddd ---"
72}
73
74--> Pattern: '\\\`\^\.\[\$\(\)\|\*\+\?\{\''; match: '\`^.[$()|*+?{''
75
76Deprecated: Function split() is deprecated in %s on line %d
77array(2) {
78  [0]=>
79  string(0) ""
80  [1]=>
81  string(38) " |1| \`^.[$()|*+?{' |2| \`^.[$()|*+?{'"
82}
83
84--> Pattern: '\a'; match: 'a'
85
86Deprecated: Function split() is deprecated in %s on line %d
87array(2) {
88  [0]=>
89  string(0) ""
90  [1]=>
91  string(12) " |1| a |2| a"
92}
93
94--> Pattern: '[0-9][^0-9]'; match: '2a'
95
96Deprecated: Function split() is deprecated in %s on line %d
97array(2) {
98  [0]=>
99  string(0) ""
100  [1]=>
101  string(14) " |1| 2a |2| 2a"
102}
103
104--> Pattern: '^[[:alnum:]]{62,62}$'; match: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
105
106Deprecated: Function split() is deprecated in %s on line %d
107array(1) {
108  [0]=>
109  string(196) "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ |1| 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ |2| 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
110}
111
112--> Pattern: '^[[:digit:]]{5}'; match: '0123456789'
113
114Deprecated: Function split() is deprecated in %s on line %d
115array(2) {
116  [0]=>
117  string(0) ""
118  [1]=>
119  string(35) "56789 |1| 0123456789 |2| 0123456789"
120}
121
122--> Pattern: '[[:digit:]]{5}$'; match: '0123456789'
123
124Deprecated: Function split() is deprecated in %s on line %d
125array(2) {
126  [0]=>
127  string(35) "0123456789 |1| 0123456789 |2| 01234"
128  [1]=>
129  string(0) ""
130}
131
132--> Pattern: '[[:blank:]]{1,10}'; match: '
133 	'
134
135Deprecated: Function split() is deprecated in %s on line %d
136array(2) {
137  [0]=>
138  string(1) "
139"
140  [1]=>
141  string(15) "|1|
142 	 |2|
143 	"
144}
145
146--> Pattern: '[[:print:]]{3}'; match: ' a '
147
148Deprecated: Function split() is deprecated in %s on line %d
149array(2) {
150  [0]=>
151  string(0) ""
152  [1]=>
153  string(16) " |1|  a  |2|  a "
154}
155Done
156