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 Only 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(5) "c:\.." 55string(4) "dir1" 56string(0) "" 57string(4) "dir1" 58array(3) { 59 ["dirname"]=> 60 string(5) "c:\.." 61 ["basename"]=> 62 string(4) "dir1" 63 ["filename"]=> 64 string(4) "dir1" 65} 66-- Iteration 2 -- 67string(23) "c:\test\..\test2\.\adir" 68string(9) "afile.txt" 69string(3) "txt" 70string(5) "afile" 71array(4) { 72 ["dirname"]=> 73 string(23) "c:\test\..\test2\.\adir" 74 ["basename"]=> 75 string(9) "afile.txt" 76 ["extension"]=> 77 string(3) "txt" 78 ["filename"]=> 79 string(5) "afile" 80} 81-- Iteration 3 -- 82string(22) "/usr/include/../arpa/." 83string(6) "inet.h" 84string(1) "h" 85string(4) "inet" 86array(4) { 87 ["dirname"]=> 88 string(22) "/usr/include/../arpa/." 89 ["basename"]=> 90 string(6) "inet.h" 91 ["extension"]=> 92 string(1) "h" 93 ["filename"]=> 94 string(4) "inet" 95} 96-- Iteration 4 -- 97string(12) "c:\test\adir" 98string(10) "afile..txt" 99string(3) "txt" 100string(6) "afile." 101array(4) { 102 ["dirname"]=> 103 string(12) "c:\test\adir" 104 ["basename"]=> 105 string(10) "afile..txt" 106 ["extension"]=> 107 string(3) "txt" 108 ["filename"]=> 109 string(6) "afile." 110} 111-- Iteration 5 -- 112string(17) "/usr/include/arpa" 113string(7) "inet..h" 114string(1) "h" 115string(5) "inet." 116array(4) { 117 ["dirname"]=> 118 string(17) "/usr/include/arpa" 119 ["basename"]=> 120 string(7) "inet..h" 121 ["extension"]=> 122 string(1) "h" 123 ["filename"]=> 124 string(5) "inet." 125} 126-- Iteration 6 -- 127string(12) "c:\test\adir" 128string(6) "afile." 129string(0) "" 130string(5) "afile" 131array(4) { 132 ["dirname"]=> 133 string(12) "c:\test\adir" 134 ["basename"]=> 135 string(6) "afile." 136 ["extension"]=> 137 string(0) "" 138 ["filename"]=> 139 string(5) "afile" 140} 141-- Iteration 7 -- 142string(17) "/usr/include/arpa" 143string(5) "inet." 144string(0) "" 145string(4) "inet" 146array(4) { 147 ["dirname"]=> 148 string(17) "/usr/include/arpa" 149 ["basename"]=> 150 string(5) "inet." 151 ["extension"]=> 152 string(0) "" 153 ["filename"]=> 154 string(4) "inet" 155} 156-- Iteration 8 -- 157string(17) "/usr/include/arpa" 158string(6) "inet,h" 159string(0) "" 160string(6) "inet,h" 161array(3) { 162 ["dirname"]=> 163 string(17) "/usr/include/arpa" 164 ["basename"]=> 165 string(6) "inet,h" 166 ["filename"]=> 167 string(6) "inet,h" 168} 169-- Iteration 9 -- 170string(3) "c:." 171string(11) "c:afile.txt" 172string(3) "txt" 173string(7) "c:afile" 174array(4) { 175 ["dirname"]=> 176 string(3) "c:." 177 ["basename"]=> 178 string(11) "c:afile.txt" 179 ["extension"]=> 180 string(3) "txt" 181 ["filename"]=> 182 string(7) "c:afile" 183} 184-- Iteration 10 -- 185string(12) "..\.\..\test" 186string(9) "afile.txt" 187string(3) "txt" 188string(5) "afile" 189array(4) { 190 ["dirname"]=> 191 string(12) "..\.\..\test" 192 ["basename"]=> 193 string(9) "afile.txt" 194 ["extension"]=> 195 string(3) "txt" 196 ["filename"]=> 197 string(5) "afile" 198} 199-- Iteration 11 -- 200string(12) ".././../test" 201string(5) "afile" 202string(0) "" 203string(5) "afile" 204array(3) { 205 ["dirname"]=> 206 string(12) ".././../test" 207 ["basename"]=> 208 string(5) "afile" 209 ["filename"]=> 210 string(5) "afile" 211} 212-- Iteration 12 -- 213string(1) "." 214string(1) "." 215string(0) "" 216string(0) "" 217array(4) { 218 ["dirname"]=> 219 string(1) "." 220 ["basename"]=> 221 string(1) "." 222 ["extension"]=> 223 string(0) "" 224 ["filename"]=> 225 string(0) "" 226} 227-- Iteration 13 -- 228string(1) "." 229string(2) ".." 230string(0) "" 231string(1) "." 232array(4) { 233 ["dirname"]=> 234 string(1) "." 235 ["basename"]=> 236 string(2) ".." 237 ["extension"]=> 238 string(0) "" 239 ["filename"]=> 240 string(1) "." 241} 242-- Iteration 14 -- 243string(1) "." 244string(3) "..." 245string(0) "" 246string(2) ".." 247array(4) { 248 ["dirname"]=> 249 string(1) "." 250 ["basename"]=> 251 string(3) "..." 252 ["extension"]=> 253 string(0) "" 254 ["filename"]=> 255 string(2) ".." 256} 257-- Iteration 15 -- 258string(12) "/usr/lib/..." 259string(5) "afile" 260string(0) "" 261string(5) "afile" 262array(3) { 263 ["dirname"]=> 264 string(12) "/usr/lib/..." 265 ["basename"]=> 266 string(5) "afile" 267 ["filename"]=> 268 string(5) "afile" 269} 270Done