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  b"$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 --
71%unicode|string%(%d) "%s/foo"
72%unicode|string%(12) "symlink.link"
73%unicode|string%(4) "link"
74%unicode|string%(7) "symlink"
75array(4) {
76  [%u|b%"dirname"]=>
77  %unicode|string%(%d) "%s/foo"
78  [%u|b%"basename"]=>
79  %unicode|string%(12) "symlink.link"
80  [%u|b%"extension"]=>
81  %unicode|string%(4) "link"
82  [%u|b%"filename"]=>
83  %unicode|string%(7) "symlink"
84}
85-- Iteration 2 --
86%unicode|string%(1) "."
87%unicode|string%(17) "www.example.co.in"
88%unicode|string%(2) "in"
89%unicode|string%(14) "www.example.co"
90array(4) {
91  [%u|b%"dirname"]=>
92  %unicode|string%(1) "."
93  [%u|b%"basename"]=>
94  %unicode|string%(17) "www.example.co.in"
95  [%u|b%"extension"]=>
96  %unicode|string%(2) "in"
97  [%u|b%"filename"]=>
98  %unicode|string%(14) "www.example.co"
99}
100-- Iteration 3 --
101%unicode|string%(13) "/var/www/html"
102%unicode|string%(12) "example.html"
103%unicode|string%(4) "html"
104%unicode|string%(7) "example"
105array(4) {
106  [%u|b%"dirname"]=>
107  %unicode|string%(13) "/var/www/html"
108  [%u|b%"basename"]=>
109  %unicode|string%(12) "example.html"
110  [%u|b%"extension"]=>
111  %unicode|string%(4) "html"
112  [%u|b%"filename"]=>
113  %unicode|string%(7) "example"
114}
115-- Iteration 4 --
116%unicode|string%(4) "/dir"
117%unicode|string%(11) "test.tar.gz"
118%unicode|string%(2) "gz"
119%unicode|string%(8) "test.tar"
120array(4) {
121  [%u|b%"dirname"]=>
122  %unicode|string%(4) "/dir"
123  [%u|b%"basename"]=>
124  %unicode|string%(11) "test.tar.gz"
125  [%u|b%"extension"]=>
126  %unicode|string%(2) "gz"
127  [%u|b%"filename"]=>
128  %unicode|string%(8) "test.tar"
129}
130-- Iteration 5 --
131%unicode|string%(%d) "%s/foo"
132%unicode|string%(12) "symlink.link"
133%unicode|string%(4) "link"
134%unicode|string%(7) "symlink"
135array(4) {
136  [%u|b%"dirname"]=>
137  %unicode|string%(%d) "%s/foo"
138  [%u|b%"basename"]=>
139  %unicode|string%(12) "symlink.link"
140  [%u|b%"extension"]=>
141  %unicode|string%(4) "link"
142  [%u|b%"filename"]=>
143  %unicode|string%(7) "symlink"
144}
145-- Iteration 6 --
146%unicode|string%(%d) "%s/foo"
147%unicode|string%(12) "symlink.link"
148%unicode|string%(4) "link"
149%unicode|string%(7) "symlink"
150array(4) {
151  [%u|b%"dirname"]=>
152  %unicode|string%(%d) "%s/foo"
153  [%u|b%"basename"]=>
154  %unicode|string%(12) "symlink.link"
155  [%u|b%"extension"]=>
156  %unicode|string%(4) "link"
157  [%u|b%"filename"]=>
158  %unicode|string%(7) "symlink"
159}
160-- Iteration 7 --
161%unicode|string%(%d) "%s/foo"
162%unicode|string%(12) "symlink.link"
163%unicode|string%(4) "link"
164%unicode|string%(7) "symlink"
165array(4) {
166  [%u|b%"dirname"]=>
167  %unicode|string%(%d) "%s/foo"
168  [%u|b%"basename"]=>
169  %unicode|string%(12) "symlink.link"
170  [%u|b%"extension"]=>
171  %unicode|string%(4) "link"
172  [%u|b%"filename"]=>
173  %unicode|string%(7) "symlink"
174}
175-- Iteration 8 --
176%unicode|string%(%d) "%s/foo"
177%unicode|string%(12) "symlink.link"
178%unicode|string%(4) "link"
179%unicode|string%(7) "symlink"
180array(4) {
181  [%u|b%"dirname"]=>
182  %unicode|string%(%d) "%s/foo"
183  [%u|b%"basename"]=>
184  %unicode|string%(12) "symlink.link"
185  [%u|b%"extension"]=>
186  %unicode|string%(4) "link"
187  [%u|b%"filename"]=>
188  %unicode|string%(7) "symlink"
189}
190-- Iteration 9 --
191%unicode|string%(%d) "%s/foo"
192%unicode|string%(12) "symlink.link"
193%unicode|string%(4) "link"
194%unicode|string%(7) "symlink"
195array(4) {
196  [%u|b%"dirname"]=>
197  %unicode|string%(%d) "%s/foo"
198  [%u|b%"basename"]=>
199  %unicode|string%(12) "symlink.link"
200  [%u|b%"extension"]=>
201  %unicode|string%(4) "link"
202  [%u|b%"filename"]=>
203  %unicode|string%(7) "symlink"
204}
205-- Iteration 10 --
206%unicode|string%(%d) "%s/foo"
207%unicode|string%(12) "symlink.link"
208%unicode|string%(4) "link"
209%unicode|string%(7) "symlink"
210array(4) {
211  [%u|b%"dirname"]=>
212  %unicode|string%(%d) "%s/foo"
213  [%u|b%"basename"]=>
214  %unicode|string%(12) "symlink.link"
215  [%u|b%"extension"]=>
216  %unicode|string%(4) "link"
217  [%u|b%"filename"]=>
218  %unicode|string%(7) "symlink"
219}
220-- Iteration 11 --
221%unicode|string%(%d) "%s/foo"
222%unicode|string%(12) "symlink.link"
223%unicode|string%(4) "link"
224%unicode|string%(7) "symlink"
225array(4) {
226  [%u|b%"dirname"]=>
227  %unicode|string%(%d) "%s/foo"
228  [%u|b%"basename"]=>
229  %unicode|string%(12) "symlink.link"
230  [%u|b%"extension"]=>
231  %unicode|string%(4) "link"
232  [%u|b%"filename"]=>
233  %unicode|string%(7) "symlink"
234}
235-- Iteration 12 --
236%unicode|string%(%d) "%s/foo"
237%unicode|string%(12) "symlink.link"
238%unicode|string%(4) "link"
239%unicode|string%(7) "symlink"
240array(4) {
241  [%u|b%"dirname"]=>
242  %unicode|string%(%d) "%s/foo"
243  [%u|b%"basename"]=>
244  %unicode|string%(12) "symlink.link"
245  [%u|b%"extension"]=>
246  %unicode|string%(4) "link"
247  [%u|b%"filename"]=>
248  %unicode|string%(7) "symlink"
249}
250-- Iteration 13 --
251string(%d) "%s/foo"
252string(12) "symlink.link"
253string(4) "link"
254string(7) "symlink"
255array(4) {
256  [%u|b%"dirname"]=>
257  string(%d) "%s/foo"
258  [%u|b%"basename"]=>
259  string(12) "symlink.link"
260  [%u|b%"extension"]=>
261  string(4) "link"
262  [%u|b%"filename"]=>
263  string(7) "symlink"
264}
265-- Iteration 14 --
266%unicode|string%(1) "."
267%unicode|string%(1) "."
268%unicode|string%(0) ""
269%unicode|string%(0) ""
270array(4) {
271  [%u|b%"dirname"]=>
272  %unicode|string%(1) "."
273  [%u|b%"basename"]=>
274  %unicode|string%(1) "."
275  [%u|b%"extension"]=>
276  %unicode|string%(0) ""
277  [%u|b%"filename"]=>
278  %unicode|string%(0) ""
279}
280-- Iteration 15 --
281%unicode|string%(%d) "%s"
282%unicode|string%(3) "foo"
283%unicode|string%(0) ""
284%unicode|string%(3) "foo"
285array(3) {
286  [%u|b%"dirname"]=>
287  %unicode|string%(%d) "%s"
288  [%u|b%"basename"]=>
289  %unicode|string%(3) "foo"
290  [%u|b%"filename"]=>
291  %unicode|string%(3) "foo"
292}
293-- Iteration 16 --
294%unicode|string%(%d) "%s"
295%unicode|string%(3) "foo"
296%unicode|string%(0) ""
297%unicode|string%(3) "foo"
298array(3) {
299  [%u|b%"dirname"]=>
300  %unicode|string%(%d) "%s"
301  [%u|b%"basename"]=>
302  %unicode|string%(3) "foo"
303  [%u|b%"filename"]=>
304  %unicode|string%(3) "foo"
305}
306-- Iteration 17 --
307%unicode|string%(%d) "%s/.."
308%unicode|string%(3) "foo"
309%unicode|string%(0) ""
310%unicode|string%(3) "foo"
311array(3) {
312  [%u|b%"dirname"]=>
313  %unicode|string%(%d) "%s/.."
314  [%u|b%"basename"]=>
315  %unicode|string%(3) "foo"
316  [%u|b%"filename"]=>
317  %unicode|string%(3) "foo"
318}
319-- Iteration 18 --
320%unicode|string%(6) "../foo"
321%unicode|string%(3) "bar"
322%unicode|string%(0) ""
323%unicode|string%(3) "bar"
324array(3) {
325  [%u|b%"dirname"]=>
326  %unicode|string%(6) "../foo"
327  [%u|b%"basename"]=>
328  %unicode|string%(3) "bar"
329  [%u|b%"filename"]=>
330  %unicode|string%(3) "bar"
331}
332-- Iteration 19 --
333%unicode|string%(5) "./foo"
334%unicode|string%(3) "bar"
335%unicode|string%(0) ""
336%unicode|string%(3) "bar"
337array(3) {
338  [%u|b%"dirname"]=>
339  %unicode|string%(5) "./foo"
340  [%u|b%"basename"]=>
341  %unicode|string%(3) "bar"
342  [%u|b%"filename"]=>
343  %unicode|string%(3) "bar"
344}
345-- Iteration 20 --
346%unicode|string%(5) "//foo"
347%unicode|string%(3) "bar"
348%unicode|string%(0) ""
349%unicode|string%(3) "bar"
350array(3) {
351  [%u|b%"dirname"]=>
352  %unicode|string%(5) "//foo"
353  [%u|b%"basename"]=>
354  %unicode|string%(3) "bar"
355  [%u|b%"filename"]=>
356  %unicode|string%(3) "bar"
357}
358-- Iteration 21 --
359%unicode|string%(5) "~/PHP"
360%unicode|string%(8) "php5.2.0"
361%unicode|string%(1) "0"
362%unicode|string%(6) "php5.2"
363array(4) {
364  [%u|b%"dirname"]=>
365  %unicode|string%(5) "~/PHP"
366  [%u|b%"basename"]=>
367  %unicode|string%(8) "php5.2.0"
368  [%u|b%"extension"]=>
369  %unicode|string%(1) "0"
370  [%u|b%"filename"]=>
371  %unicode|string%(6) "php5.2"
372}
373-- Iteration 22 --
374%unicode|string%(13) "/home/example"
375%unicode|string%(4) "test"
376%unicode|string%(0) ""
377%unicode|string%(4) "test"
378array(3) {
379  [%u|b%"dirname"]=>
380  %unicode|string%(13) "/home/example"
381  [%u|b%"basename"]=>
382  %unicode|string%(4) "test"
383  [%u|b%"filename"]=>
384  %unicode|string%(4) "test"
385}
386-- Iteration 23 --
387%unicode|string%(23) "http://httpd.apache.org"
388%unicode|string%(24) "core.html#acceptpathinfo"
389%unicode|string%(19) "html#acceptpathinfo"
390%unicode|string%(4) "core"
391array(4) {
392  [%u|b%"dirname"]=>
393  %unicode|string%(23) "http://httpd.apache.org"
394  [%u|b%"basename"]=>
395  %unicode|string%(24) "core.html#acceptpathinfo"
396  [%u|b%"extension"]=>
397  %unicode|string%(19) "html#acceptpathinfo"
398  [%u|b%"filename"]=>
399  %unicode|string%(4) "core"
400}
401Done
402