1--TEST--
2Test pathinfo() function: basic functionality
3--FILE--
4<?php
5echo "*** Testing basic functions of pathinfo() ***\n";
6
7$file_path = __DIR__;
8
9$paths = array (
10  /* Testing basic file notation */
11  "$file_path/foo/symlink.link",
12  "www.example.co.in",
13  "/var/www/html/example.html",
14  "/dir/test.tar.gz",
15
16  /* Testing a file with trailing slash */
17  "$file_path/foo/symlink.link/",
18
19  /* Testing file with double slashes */
20  "$file_path/foo//symlink.link",
21  "$file_path/foo//symlink.link",
22  "$file_path/foo//symlink.link//",
23
24  /* Testing file with trailing double slashes */
25  "$file_path/foo/symlink.link//",
26
27  /* Testing Binary safe files */
28  "$file_path/foo".chr(47)."symlink.link",
29  "$file_path".chr(47)."foo/symlink.link",
30  "$file_path".chr(47)."foo".chr(47)."symlink.link",
31  "$file_path/foo/symlink.link",
32
33  /* Testing directories */
34  ".",  // current directory
35  "$file_path/foo/",
36  "$file_path/foo//",
37  "$file_path/../foo/",
38  "../foo/bar",
39  "./foo/bar",
40  "//foo//bar//",
41
42  /* Testing with homedir notation */
43  "~/PHP/php5.2.0/",
44
45  /* Testing normal directory notation */
46  "/home/example/test/",
47  "http://httpd.apache.org/core.html#acceptpathinfo"
48);
49
50$counter = 1;
51/* loop through $paths to test each $path in the above array */
52foreach($paths as $path) {
53  echo "-- Iteration $counter --\n";
54  var_dump( pathinfo($path, PATHINFO_DIRNAME) );
55  var_dump( pathinfo($path, PATHINFO_BASENAME) );
56  var_dump( pathinfo($path, PATHINFO_EXTENSION) );
57  var_dump( pathinfo($path, PATHINFO_FILENAME) );
58  var_dump( pathinfo($path) );
59  $counter++;
60}
61
62echo "Done\n";
63?>
64--EXPECTF--
65*** Testing basic functions of pathinfo() ***
66-- Iteration 1 --
67string(%d) "%s/foo"
68string(12) "symlink.link"
69string(4) "link"
70string(7) "symlink"
71array(4) {
72  ["dirname"]=>
73  string(%d) "%s/foo"
74  ["basename"]=>
75  string(12) "symlink.link"
76  ["extension"]=>
77  string(4) "link"
78  ["filename"]=>
79  string(7) "symlink"
80}
81-- Iteration 2 --
82string(1) "."
83string(17) "www.example.co.in"
84string(2) "in"
85string(14) "www.example.co"
86array(4) {
87  ["dirname"]=>
88  string(1) "."
89  ["basename"]=>
90  string(17) "www.example.co.in"
91  ["extension"]=>
92  string(2) "in"
93  ["filename"]=>
94  string(14) "www.example.co"
95}
96-- Iteration 3 --
97string(13) "/var/www/html"
98string(12) "example.html"
99string(4) "html"
100string(7) "example"
101array(4) {
102  ["dirname"]=>
103  string(13) "/var/www/html"
104  ["basename"]=>
105  string(12) "example.html"
106  ["extension"]=>
107  string(4) "html"
108  ["filename"]=>
109  string(7) "example"
110}
111-- Iteration 4 --
112string(4) "/dir"
113string(11) "test.tar.gz"
114string(2) "gz"
115string(8) "test.tar"
116array(4) {
117  ["dirname"]=>
118  string(4) "/dir"
119  ["basename"]=>
120  string(11) "test.tar.gz"
121  ["extension"]=>
122  string(2) "gz"
123  ["filename"]=>
124  string(8) "test.tar"
125}
126-- Iteration 5 --
127string(%d) "%s/foo"
128string(12) "symlink.link"
129string(4) "link"
130string(7) "symlink"
131array(4) {
132  ["dirname"]=>
133  string(%d) "%s/foo"
134  ["basename"]=>
135  string(12) "symlink.link"
136  ["extension"]=>
137  string(4) "link"
138  ["filename"]=>
139  string(7) "symlink"
140}
141-- Iteration 6 --
142string(%d) "%s/foo"
143string(12) "symlink.link"
144string(4) "link"
145string(7) "symlink"
146array(4) {
147  ["dirname"]=>
148  string(%d) "%s/foo"
149  ["basename"]=>
150  string(12) "symlink.link"
151  ["extension"]=>
152  string(4) "link"
153  ["filename"]=>
154  string(7) "symlink"
155}
156-- Iteration 7 --
157string(%d) "%s/foo"
158string(12) "symlink.link"
159string(4) "link"
160string(7) "symlink"
161array(4) {
162  ["dirname"]=>
163  string(%d) "%s/foo"
164  ["basename"]=>
165  string(12) "symlink.link"
166  ["extension"]=>
167  string(4) "link"
168  ["filename"]=>
169  string(7) "symlink"
170}
171-- Iteration 8 --
172string(%d) "%s/foo"
173string(12) "symlink.link"
174string(4) "link"
175string(7) "symlink"
176array(4) {
177  ["dirname"]=>
178  string(%d) "%s/foo"
179  ["basename"]=>
180  string(12) "symlink.link"
181  ["extension"]=>
182  string(4) "link"
183  ["filename"]=>
184  string(7) "symlink"
185}
186-- Iteration 9 --
187string(%d) "%s/foo"
188string(12) "symlink.link"
189string(4) "link"
190string(7) "symlink"
191array(4) {
192  ["dirname"]=>
193  string(%d) "%s/foo"
194  ["basename"]=>
195  string(12) "symlink.link"
196  ["extension"]=>
197  string(4) "link"
198  ["filename"]=>
199  string(7) "symlink"
200}
201-- Iteration 10 --
202string(%d) "%s/foo"
203string(12) "symlink.link"
204string(4) "link"
205string(7) "symlink"
206array(4) {
207  ["dirname"]=>
208  string(%d) "%s/foo"
209  ["basename"]=>
210  string(12) "symlink.link"
211  ["extension"]=>
212  string(4) "link"
213  ["filename"]=>
214  string(7) "symlink"
215}
216-- Iteration 11 --
217string(%d) "%s/foo"
218string(12) "symlink.link"
219string(4) "link"
220string(7) "symlink"
221array(4) {
222  ["dirname"]=>
223  string(%d) "%s/foo"
224  ["basename"]=>
225  string(12) "symlink.link"
226  ["extension"]=>
227  string(4) "link"
228  ["filename"]=>
229  string(7) "symlink"
230}
231-- Iteration 12 --
232string(%d) "%s/foo"
233string(12) "symlink.link"
234string(4) "link"
235string(7) "symlink"
236array(4) {
237  ["dirname"]=>
238  string(%d) "%s/foo"
239  ["basename"]=>
240  string(12) "symlink.link"
241  ["extension"]=>
242  string(4) "link"
243  ["filename"]=>
244  string(7) "symlink"
245}
246-- Iteration 13 --
247string(%d) "%s/foo"
248string(12) "symlink.link"
249string(4) "link"
250string(7) "symlink"
251array(4) {
252  ["dirname"]=>
253  string(%d) "%s/foo"
254  ["basename"]=>
255  string(12) "symlink.link"
256  ["extension"]=>
257  string(4) "link"
258  ["filename"]=>
259  string(7) "symlink"
260}
261-- Iteration 14 --
262string(1) "."
263string(1) "."
264string(0) ""
265string(0) ""
266array(4) {
267  ["dirname"]=>
268  string(1) "."
269  ["basename"]=>
270  string(1) "."
271  ["extension"]=>
272  string(0) ""
273  ["filename"]=>
274  string(0) ""
275}
276-- Iteration 15 --
277string(%d) "%s"
278string(3) "foo"
279string(0) ""
280string(3) "foo"
281array(3) {
282  ["dirname"]=>
283  string(%d) "%s"
284  ["basename"]=>
285  string(3) "foo"
286  ["filename"]=>
287  string(3) "foo"
288}
289-- Iteration 16 --
290string(%d) "%s"
291string(3) "foo"
292string(0) ""
293string(3) "foo"
294array(3) {
295  ["dirname"]=>
296  string(%d) "%s"
297  ["basename"]=>
298  string(3) "foo"
299  ["filename"]=>
300  string(3) "foo"
301}
302-- Iteration 17 --
303string(%d) "%s/.."
304string(3) "foo"
305string(0) ""
306string(3) "foo"
307array(3) {
308  ["dirname"]=>
309  string(%d) "%s/.."
310  ["basename"]=>
311  string(3) "foo"
312  ["filename"]=>
313  string(3) "foo"
314}
315-- Iteration 18 --
316string(6) "../foo"
317string(3) "bar"
318string(0) ""
319string(3) "bar"
320array(3) {
321  ["dirname"]=>
322  string(6) "../foo"
323  ["basename"]=>
324  string(3) "bar"
325  ["filename"]=>
326  string(3) "bar"
327}
328-- Iteration 19 --
329string(5) "./foo"
330string(3) "bar"
331string(0) ""
332string(3) "bar"
333array(3) {
334  ["dirname"]=>
335  string(5) "./foo"
336  ["basename"]=>
337  string(3) "bar"
338  ["filename"]=>
339  string(3) "bar"
340}
341-- Iteration 20 --
342string(5) "//foo"
343string(3) "bar"
344string(0) ""
345string(3) "bar"
346array(3) {
347  ["dirname"]=>
348  string(5) "//foo"
349  ["basename"]=>
350  string(3) "bar"
351  ["filename"]=>
352  string(3) "bar"
353}
354-- Iteration 21 --
355string(5) "~/PHP"
356string(8) "php5.2.0"
357string(1) "0"
358string(6) "php5.2"
359array(4) {
360  ["dirname"]=>
361  string(5) "~/PHP"
362  ["basename"]=>
363  string(8) "php5.2.0"
364  ["extension"]=>
365  string(1) "0"
366  ["filename"]=>
367  string(6) "php5.2"
368}
369-- Iteration 22 --
370string(13) "/home/example"
371string(4) "test"
372string(0) ""
373string(4) "test"
374array(3) {
375  ["dirname"]=>
376  string(13) "/home/example"
377  ["basename"]=>
378  string(4) "test"
379  ["filename"]=>
380  string(4) "test"
381}
382-- Iteration 23 --
383string(23) "http://httpd.apache.org"
384string(24) "core.html#acceptpathinfo"
385string(19) "html#acceptpathinfo"
386string(4) "core"
387array(4) {
388  ["dirname"]=>
389  string(23) "http://httpd.apache.org"
390  ["basename"]=>
391  string(24) "core.html#acceptpathinfo"
392  ["extension"]=>
393  string(19) "html#acceptpathinfo"
394  ["filename"]=>
395  string(4) "core"
396}
397Done
398