1--TEST--
2basename() with various inputs
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) == 'WIN') {
6    die('skip non-windows only test');
7}
8?>
9--FILE--
10<?php
11
12$prefixes = array (
13
14    // drive letters
15	"A:/",
16    "Z:/",
17    "A:\\",
18
19    // other prefixes
20    "http://",
21    "blah://",
22	"blah:\\",
23    "hostname:",
24
25	// home directory ~
26	"~/",
27	"~\\",
28);
29
30$paths = array (
31
32	"foo",
33	"foo/",
34    "foo\\",
35    "foo.bar",
36    "foo.bar/",
37    "foo.bar\\",
38    "dir/foo.bar",
39    "dir\\foo.bar",
40    "dir with spaces/foo.bar",
41    "dir with spaces\\foo.bar",
42
43);
44
45foreach ($prefixes as $prefix) {
46	foreach ($paths as $path) {
47		$input = $prefix . $path;
48		echo "basename for path $input is:\n";
49		var_dump(basename($input));
50	}
51}
52
53echo "\ndone\n";
54
55?>
56--EXPECT--
57basename for path A:/foo is:
58string(3) "foo"
59basename for path A:/foo/ is:
60string(3) "foo"
61basename for path A:/foo\ is:
62string(4) "foo\"
63basename for path A:/foo.bar is:
64string(7) "foo.bar"
65basename for path A:/foo.bar/ is:
66string(7) "foo.bar"
67basename for path A:/foo.bar\ is:
68string(8) "foo.bar\"
69basename for path A:/dir/foo.bar is:
70string(7) "foo.bar"
71basename for path A:/dir\foo.bar is:
72string(11) "dir\foo.bar"
73basename for path A:/dir with spaces/foo.bar is:
74string(7) "foo.bar"
75basename for path A:/dir with spaces\foo.bar is:
76string(23) "dir with spaces\foo.bar"
77basename for path Z:/foo is:
78string(3) "foo"
79basename for path Z:/foo/ is:
80string(3) "foo"
81basename for path Z:/foo\ is:
82string(4) "foo\"
83basename for path Z:/foo.bar is:
84string(7) "foo.bar"
85basename for path Z:/foo.bar/ is:
86string(7) "foo.bar"
87basename for path Z:/foo.bar\ is:
88string(8) "foo.bar\"
89basename for path Z:/dir/foo.bar is:
90string(7) "foo.bar"
91basename for path Z:/dir\foo.bar is:
92string(11) "dir\foo.bar"
93basename for path Z:/dir with spaces/foo.bar is:
94string(7) "foo.bar"
95basename for path Z:/dir with spaces\foo.bar is:
96string(23) "dir with spaces\foo.bar"
97basename for path A:\foo is:
98string(6) "A:\foo"
99basename for path A:\foo/ is:
100string(6) "A:\foo"
101basename for path A:\foo\ is:
102string(7) "A:\foo\"
103basename for path A:\foo.bar is:
104string(10) "A:\foo.bar"
105basename for path A:\foo.bar/ is:
106string(10) "A:\foo.bar"
107basename for path A:\foo.bar\ is:
108string(11) "A:\foo.bar\"
109basename for path A:\dir/foo.bar is:
110string(7) "foo.bar"
111basename for path A:\dir\foo.bar is:
112string(14) "A:\dir\foo.bar"
113basename for path A:\dir with spaces/foo.bar is:
114string(7) "foo.bar"
115basename for path A:\dir with spaces\foo.bar is:
116string(26) "A:\dir with spaces\foo.bar"
117basename for path http://foo is:
118string(3) "foo"
119basename for path http://foo/ is:
120string(3) "foo"
121basename for path http://foo\ is:
122string(4) "foo\"
123basename for path http://foo.bar is:
124string(7) "foo.bar"
125basename for path http://foo.bar/ is:
126string(7) "foo.bar"
127basename for path http://foo.bar\ is:
128string(8) "foo.bar\"
129basename for path http://dir/foo.bar is:
130string(7) "foo.bar"
131basename for path http://dir\foo.bar is:
132string(11) "dir\foo.bar"
133basename for path http://dir with spaces/foo.bar is:
134string(7) "foo.bar"
135basename for path http://dir with spaces\foo.bar is:
136string(23) "dir with spaces\foo.bar"
137basename for path blah://foo is:
138string(3) "foo"
139basename for path blah://foo/ is:
140string(3) "foo"
141basename for path blah://foo\ is:
142string(4) "foo\"
143basename for path blah://foo.bar is:
144string(7) "foo.bar"
145basename for path blah://foo.bar/ is:
146string(7) "foo.bar"
147basename for path blah://foo.bar\ is:
148string(8) "foo.bar\"
149basename for path blah://dir/foo.bar is:
150string(7) "foo.bar"
151basename for path blah://dir\foo.bar is:
152string(11) "dir\foo.bar"
153basename for path blah://dir with spaces/foo.bar is:
154string(7) "foo.bar"
155basename for path blah://dir with spaces\foo.bar is:
156string(23) "dir with spaces\foo.bar"
157basename for path blah:\foo is:
158string(9) "blah:\foo"
159basename for path blah:\foo/ is:
160string(9) "blah:\foo"
161basename for path blah:\foo\ is:
162string(10) "blah:\foo\"
163basename for path blah:\foo.bar is:
164string(13) "blah:\foo.bar"
165basename for path blah:\foo.bar/ is:
166string(13) "blah:\foo.bar"
167basename for path blah:\foo.bar\ is:
168string(14) "blah:\foo.bar\"
169basename for path blah:\dir/foo.bar is:
170string(7) "foo.bar"
171basename for path blah:\dir\foo.bar is:
172string(17) "blah:\dir\foo.bar"
173basename for path blah:\dir with spaces/foo.bar is:
174string(7) "foo.bar"
175basename for path blah:\dir with spaces\foo.bar is:
176string(29) "blah:\dir with spaces\foo.bar"
177basename for path hostname:foo is:
178string(12) "hostname:foo"
179basename for path hostname:foo/ is:
180string(12) "hostname:foo"
181basename for path hostname:foo\ is:
182string(13) "hostname:foo\"
183basename for path hostname:foo.bar is:
184string(16) "hostname:foo.bar"
185basename for path hostname:foo.bar/ is:
186string(16) "hostname:foo.bar"
187basename for path hostname:foo.bar\ is:
188string(17) "hostname:foo.bar\"
189basename for path hostname:dir/foo.bar is:
190string(7) "foo.bar"
191basename for path hostname:dir\foo.bar is:
192string(20) "hostname:dir\foo.bar"
193basename for path hostname:dir with spaces/foo.bar is:
194string(7) "foo.bar"
195basename for path hostname:dir with spaces\foo.bar is:
196string(32) "hostname:dir with spaces\foo.bar"
197basename for path ~/foo is:
198string(3) "foo"
199basename for path ~/foo/ is:
200string(3) "foo"
201basename for path ~/foo\ is:
202string(4) "foo\"
203basename for path ~/foo.bar is:
204string(7) "foo.bar"
205basename for path ~/foo.bar/ is:
206string(7) "foo.bar"
207basename for path ~/foo.bar\ is:
208string(8) "foo.bar\"
209basename for path ~/dir/foo.bar is:
210string(7) "foo.bar"
211basename for path ~/dir\foo.bar is:
212string(11) "dir\foo.bar"
213basename for path ~/dir with spaces/foo.bar is:
214string(7) "foo.bar"
215basename for path ~/dir with spaces\foo.bar is:
216string(23) "dir with spaces\foo.bar"
217basename for path ~\foo is:
218string(5) "~\foo"
219basename for path ~\foo/ is:
220string(5) "~\foo"
221basename for path ~\foo\ is:
222string(6) "~\foo\"
223basename for path ~\foo.bar is:
224string(9) "~\foo.bar"
225basename for path ~\foo.bar/ is:
226string(9) "~\foo.bar"
227basename for path ~\foo.bar\ is:
228string(10) "~\foo.bar\"
229basename for path ~\dir/foo.bar is:
230string(7) "foo.bar"
231basename for path ~\dir\foo.bar is:
232string(13) "~\dir\foo.bar"
233basename for path ~\dir with spaces/foo.bar is:
234string(7) "foo.bar"
235basename for path ~\dir with spaces\foo.bar is:
236string(25) "~\dir with spaces\foo.bar"
237
238done
239