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