1--TEST--
2basename() with various inputs
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) != 'WIN') {
6    die('skip Windows only basename tests');
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(3) "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(7) "foo.bar"
69basename for path A:/dir/foo.bar is:
70string(7) "foo.bar"
71basename for path A:/dir\foo.bar is:
72string(7) "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(7) "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(3) "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(7) "foo.bar"
89basename for path Z:/dir/foo.bar is:
90string(7) "foo.bar"
91basename for path Z:/dir\foo.bar is:
92string(7) "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(7) "foo.bar"
97basename for path A:\foo is:
98string(3) "foo"
99basename for path A:\foo/ is:
100string(3) "foo"
101basename for path A:\foo\ is:
102string(3) "foo"
103basename for path A:\foo.bar is:
104string(7) "foo.bar"
105basename for path A:\foo.bar/ is:
106string(7) "foo.bar"
107basename for path A:\foo.bar\ is:
108string(7) "foo.bar"
109basename for path A:\dir/foo.bar is:
110string(7) "foo.bar"
111basename for path A:\dir\foo.bar is:
112string(7) "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(7) "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(3) "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(7) "foo.bar"
129basename for path http://dir/foo.bar is:
130string(7) "foo.bar"
131basename for path http://dir\foo.bar is:
132string(7) "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(7) "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(3) "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(7) "foo.bar"
149basename for path blah://dir/foo.bar is:
150string(7) "foo.bar"
151basename for path blah://dir\foo.bar is:
152string(7) "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(7) "foo.bar"
157basename for path blah:\foo is:
158string(3) "foo"
159basename for path blah:\foo/ is:
160string(3) "foo"
161basename for path blah:\foo\ is:
162string(3) "foo"
163basename for path blah:\foo.bar is:
164string(7) "foo.bar"
165basename for path blah:\foo.bar/ is:
166string(7) "foo.bar"
167basename for path blah:\foo.bar\ is:
168string(7) "foo.bar"
169basename for path blah:\dir/foo.bar is:
170string(7) "foo.bar"
171basename for path blah:\dir\foo.bar is:
172string(7) "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(7) "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(12) "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(16) "hostname:foo.bar"
189basename for path hostname:dir/foo.bar is:
190string(7) "foo.bar"
191basename for path hostname:dir\foo.bar is:
192string(7) "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(7) "foo.bar"
197basename for path ~/foo is:
198string(3) "foo"
199basename for path ~/foo/ is:
200string(3) "foo"
201basename for path ~/foo\ is:
202string(3) "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(7) "foo.bar"
209basename for path ~/dir/foo.bar is:
210string(7) "foo.bar"
211basename for path ~/dir\foo.bar is:
212string(7) "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(7) "foo.bar"
217basename for path ~\foo is:
218string(3) "foo"
219basename for path ~\foo/ is:
220string(3) "foo"
221basename for path ~\foo\ is:
222string(3) "foo"
223basename for path ~\foo.bar is:
224string(7) "foo.bar"
225basename for path ~\foo.bar/ is:
226string(7) "foo.bar"
227basename for path ~\foo.bar\ is:
228string(7) "foo.bar"
229basename for path ~\dir/foo.bar is:
230string(7) "foo.bar"
231basename for path ~\dir\foo.bar is:
232string(7) "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(7) "foo.bar"
237
238done
239