1--TEST-- 2Test pathinfo() function: basic functionality 3--CREDITS-- 4Dave Kelsey <d_kelsey@uk.ibm.com> 5--SKIPIF-- 6<?php 7if(substr(PHP_OS, 0, 3) == "WIN") 8 die("skip Not valid for Windows"); 9?> 10--FILE-- 11<?php 12/* Prototype: mixed pathinfo ( string $path [, int $options] ); 13 Description: Returns information about a file path 14*/ 15 16echo "*** Testing basic functions of pathinfo() ***\n"; 17 18$paths = array ( 19 'c:\..\dir1', 20 'c:\test\..\test2\.\adir\afile.txt', 21 '/usr/include/../arpa/./inet.h', 22 'c:\test\adir\afile..txt', 23 '/usr/include/arpa/inet..h', 24 'c:\test\adir\afile.', 25 '/usr/include/arpa/inet.', 26 '/usr/include/arpa/inet,h', 27 'c:afile.txt', 28 '..\.\..\test\afile.txt', 29 '.././../test/afile', 30 '.', 31 '..', 32 '...', 33 '/usr/lib/.../afile' 34 35); 36 37$counter = 1; 38/* loop through $paths to test each $path in the above array */ 39foreach($paths as $path) { 40 echo "-- Iteration $counter --\n"; 41 var_dump( pathinfo($path, PATHINFO_DIRNAME) ); 42 var_dump( pathinfo($path, PATHINFO_BASENAME) ); 43 var_dump( pathinfo($path, PATHINFO_EXTENSION) ); 44 var_dump( pathinfo($path, PATHINFO_FILENAME) ); 45 var_dump( pathinfo($path) ); 46 $counter++; 47} 48 49echo "Done\n"; 50?> 51--EXPECT-- 52*** Testing basic functions of pathinfo() *** 53-- Iteration 1 -- 54string(1) "." 55string(10) "c:\..\dir1" 56string(5) "\dir1" 57string(4) "c:\." 58array(4) { 59 ["dirname"]=> 60 string(1) "." 61 ["basename"]=> 62 string(10) "c:\..\dir1" 63 ["extension"]=> 64 string(5) "\dir1" 65 ["filename"]=> 66 string(4) "c:\." 67} 68-- Iteration 2 -- 69string(1) "." 70string(33) "c:\test\..\test2\.\adir\afile.txt" 71string(3) "txt" 72string(29) "c:\test\..\test2\.\adir\afile" 73array(4) { 74 ["dirname"]=> 75 string(1) "." 76 ["basename"]=> 77 string(33) "c:\test\..\test2\.\adir\afile.txt" 78 ["extension"]=> 79 string(3) "txt" 80 ["filename"]=> 81 string(29) "c:\test\..\test2\.\adir\afile" 82} 83-- Iteration 3 -- 84string(22) "/usr/include/../arpa/." 85string(6) "inet.h" 86string(1) "h" 87string(4) "inet" 88array(4) { 89 ["dirname"]=> 90 string(22) "/usr/include/../arpa/." 91 ["basename"]=> 92 string(6) "inet.h" 93 ["extension"]=> 94 string(1) "h" 95 ["filename"]=> 96 string(4) "inet" 97} 98-- Iteration 4 -- 99string(1) "." 100string(23) "c:\test\adir\afile..txt" 101string(3) "txt" 102string(19) "c:\test\adir\afile." 103array(4) { 104 ["dirname"]=> 105 string(1) "." 106 ["basename"]=> 107 string(23) "c:\test\adir\afile..txt" 108 ["extension"]=> 109 string(3) "txt" 110 ["filename"]=> 111 string(19) "c:\test\adir\afile." 112} 113-- Iteration 5 -- 114string(17) "/usr/include/arpa" 115string(7) "inet..h" 116string(1) "h" 117string(5) "inet." 118array(4) { 119 ["dirname"]=> 120 string(17) "/usr/include/arpa" 121 ["basename"]=> 122 string(7) "inet..h" 123 ["extension"]=> 124 string(1) "h" 125 ["filename"]=> 126 string(5) "inet." 127} 128-- Iteration 6 -- 129string(1) "." 130string(19) "c:\test\adir\afile." 131string(0) "" 132string(18) "c:\test\adir\afile" 133array(4) { 134 ["dirname"]=> 135 string(1) "." 136 ["basename"]=> 137 string(19) "c:\test\adir\afile." 138 ["extension"]=> 139 string(0) "" 140 ["filename"]=> 141 string(18) "c:\test\adir\afile" 142} 143-- Iteration 7 -- 144string(17) "/usr/include/arpa" 145string(5) "inet." 146string(0) "" 147string(4) "inet" 148array(4) { 149 ["dirname"]=> 150 string(17) "/usr/include/arpa" 151 ["basename"]=> 152 string(5) "inet." 153 ["extension"]=> 154 string(0) "" 155 ["filename"]=> 156 string(4) "inet" 157} 158-- Iteration 8 -- 159string(17) "/usr/include/arpa" 160string(6) "inet,h" 161string(0) "" 162string(6) "inet,h" 163array(3) { 164 ["dirname"]=> 165 string(17) "/usr/include/arpa" 166 ["basename"]=> 167 string(6) "inet,h" 168 ["filename"]=> 169 string(6) "inet,h" 170} 171-- Iteration 9 -- 172string(1) "." 173string(11) "c:afile.txt" 174string(3) "txt" 175string(7) "c:afile" 176array(4) { 177 ["dirname"]=> 178 string(1) "." 179 ["basename"]=> 180 string(11) "c:afile.txt" 181 ["extension"]=> 182 string(3) "txt" 183 ["filename"]=> 184 string(7) "c:afile" 185} 186-- Iteration 10 -- 187string(1) "." 188string(22) "..\.\..\test\afile.txt" 189string(3) "txt" 190string(18) "..\.\..\test\afile" 191array(4) { 192 ["dirname"]=> 193 string(1) "." 194 ["basename"]=> 195 string(22) "..\.\..\test\afile.txt" 196 ["extension"]=> 197 string(3) "txt" 198 ["filename"]=> 199 string(18) "..\.\..\test\afile" 200} 201-- Iteration 11 -- 202string(12) ".././../test" 203string(5) "afile" 204string(0) "" 205string(5) "afile" 206array(3) { 207 ["dirname"]=> 208 string(12) ".././../test" 209 ["basename"]=> 210 string(5) "afile" 211 ["filename"]=> 212 string(5) "afile" 213} 214-- Iteration 12 -- 215string(1) "." 216string(1) "." 217string(0) "" 218string(0) "" 219array(4) { 220 ["dirname"]=> 221 string(1) "." 222 ["basename"]=> 223 string(1) "." 224 ["extension"]=> 225 string(0) "" 226 ["filename"]=> 227 string(0) "" 228} 229-- Iteration 13 -- 230string(1) "." 231string(2) ".." 232string(0) "" 233string(1) "." 234array(4) { 235 ["dirname"]=> 236 string(1) "." 237 ["basename"]=> 238 string(2) ".." 239 ["extension"]=> 240 string(0) "" 241 ["filename"]=> 242 string(1) "." 243} 244-- Iteration 14 -- 245string(1) "." 246string(3) "..." 247string(0) "" 248string(2) ".." 249array(4) { 250 ["dirname"]=> 251 string(1) "." 252 ["basename"]=> 253 string(3) "..." 254 ["extension"]=> 255 string(0) "" 256 ["filename"]=> 257 string(2) ".." 258} 259-- Iteration 15 -- 260string(12) "/usr/lib/..." 261string(5) "afile" 262string(0) "" 263string(5) "afile" 264array(3) { 265 ["dirname"]=> 266 string(12) "/usr/lib/..." 267 ["basename"]=> 268 string(5) "afile" 269 ["filename"]=> 270 string(5) "afile" 271} 272Done 273