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 '', 20 ' ', 21 'c:', 22 'c:\\', 23 'c:/', 24 'afile', 25 'c:\test\adir', 26 'c:\test\adir\\', 27 '/usr/include/arpa', 28 '/usr/include/arpa/', 29 'usr/include/arpa', 30 'usr/include/arpa/', 31 'c:\test\afile', 32 'c:\\test\\afile', 33 'c://test//afile', 34 'c:\test\afile\\', 35 'c:\test\prog.exe', 36 'c:\\test\\prog.exe', 37 'c:/test/prog.exe', 38 '/usr/include/arpa/inet.h', 39 '//usr/include//arpa/inet.h', 40 '\\', 41 '\\\\', 42 '/', 43 '//', 44 '///', 45 '/usr/include/arpa/inet.h', 46 'c:\windows/system32\drivers/etc\hosts', 47 '/usr\include/arpa\inet.h', 48 ' c:\test\adir\afile.txt', 49 'c:\test\adir\afile.txt ', 50 ' c:\test\adir\afile.txt ', 51 ' /usr/include/arpa/inet.h', 52 '/usr/include/arpa/inet.h ', 53 ' /usr/include/arpa/inet.h ', 54 ' c:', 55 ' c:\test\adir\afile.txt', 56 '/usr', 57 '/usr/' 58); 59 60$counter = 1; 61/* loop through $paths to test each $path in the above array */ 62foreach($paths as $path) { 63 echo "-- Iteration $counter --\n"; 64 var_dump( pathinfo($path, PATHINFO_DIRNAME) ); 65 var_dump( pathinfo($path, PATHINFO_BASENAME) ); 66 var_dump( pathinfo($path, PATHINFO_EXTENSION) ); 67 var_dump( pathinfo($path, PATHINFO_FILENAME) ); 68 var_dump( pathinfo($path) ); 69 $counter++; 70} 71 72echo "Done\n"; 73?> 74--EXPECT-- 75*** Testing basic functions of pathinfo() *** 76-- Iteration 1 -- 77string(0) "" 78string(0) "" 79string(0) "" 80string(0) "" 81array(2) { 82 ["basename"]=> 83 string(0) "" 84 ["filename"]=> 85 string(0) "" 86} 87-- Iteration 2 -- 88string(1) "." 89string(1) " " 90string(0) "" 91string(1) " " 92array(3) { 93 ["dirname"]=> 94 string(1) "." 95 ["basename"]=> 96 string(1) " " 97 ["filename"]=> 98 string(1) " " 99} 100-- Iteration 3 -- 101string(1) "." 102string(2) "c:" 103string(0) "" 104string(2) "c:" 105array(3) { 106 ["dirname"]=> 107 string(1) "." 108 ["basename"]=> 109 string(2) "c:" 110 ["filename"]=> 111 string(2) "c:" 112} 113-- Iteration 4 -- 114string(1) "." 115string(3) "c:\" 116string(0) "" 117string(3) "c:\" 118array(3) { 119 ["dirname"]=> 120 string(1) "." 121 ["basename"]=> 122 string(3) "c:\" 123 ["filename"]=> 124 string(3) "c:\" 125} 126-- Iteration 5 -- 127string(1) "." 128string(2) "c:" 129string(0) "" 130string(2) "c:" 131array(3) { 132 ["dirname"]=> 133 string(1) "." 134 ["basename"]=> 135 string(2) "c:" 136 ["filename"]=> 137 string(2) "c:" 138} 139-- Iteration 6 -- 140string(1) "." 141string(5) "afile" 142string(0) "" 143string(5) "afile" 144array(3) { 145 ["dirname"]=> 146 string(1) "." 147 ["basename"]=> 148 string(5) "afile" 149 ["filename"]=> 150 string(5) "afile" 151} 152-- Iteration 7 -- 153string(1) "." 154string(12) "c:\test\adir" 155string(0) "" 156string(12) "c:\test\adir" 157array(3) { 158 ["dirname"]=> 159 string(1) "." 160 ["basename"]=> 161 string(12) "c:\test\adir" 162 ["filename"]=> 163 string(12) "c:\test\adir" 164} 165-- Iteration 8 -- 166string(1) "." 167string(13) "c:\test\adir\" 168string(0) "" 169string(13) "c:\test\adir\" 170array(3) { 171 ["dirname"]=> 172 string(1) "." 173 ["basename"]=> 174 string(13) "c:\test\adir\" 175 ["filename"]=> 176 string(13) "c:\test\adir\" 177} 178-- Iteration 9 -- 179string(12) "/usr/include" 180string(4) "arpa" 181string(0) "" 182string(4) "arpa" 183array(3) { 184 ["dirname"]=> 185 string(12) "/usr/include" 186 ["basename"]=> 187 string(4) "arpa" 188 ["filename"]=> 189 string(4) "arpa" 190} 191-- Iteration 10 -- 192string(12) "/usr/include" 193string(4) "arpa" 194string(0) "" 195string(4) "arpa" 196array(3) { 197 ["dirname"]=> 198 string(12) "/usr/include" 199 ["basename"]=> 200 string(4) "arpa" 201 ["filename"]=> 202 string(4) "arpa" 203} 204-- Iteration 11 -- 205string(11) "usr/include" 206string(4) "arpa" 207string(0) "" 208string(4) "arpa" 209array(3) { 210 ["dirname"]=> 211 string(11) "usr/include" 212 ["basename"]=> 213 string(4) "arpa" 214 ["filename"]=> 215 string(4) "arpa" 216} 217-- Iteration 12 -- 218string(11) "usr/include" 219string(4) "arpa" 220string(0) "" 221string(4) "arpa" 222array(3) { 223 ["dirname"]=> 224 string(11) "usr/include" 225 ["basename"]=> 226 string(4) "arpa" 227 ["filename"]=> 228 string(4) "arpa" 229} 230-- Iteration 13 -- 231string(1) "." 232string(13) "c:\test\afile" 233string(0) "" 234string(13) "c:\test\afile" 235array(3) { 236 ["dirname"]=> 237 string(1) "." 238 ["basename"]=> 239 string(13) "c:\test\afile" 240 ["filename"]=> 241 string(13) "c:\test\afile" 242} 243-- Iteration 14 -- 244string(1) "." 245string(13) "c:\test\afile" 246string(0) "" 247string(13) "c:\test\afile" 248array(3) { 249 ["dirname"]=> 250 string(1) "." 251 ["basename"]=> 252 string(13) "c:\test\afile" 253 ["filename"]=> 254 string(13) "c:\test\afile" 255} 256-- Iteration 15 -- 257string(8) "c://test" 258string(5) "afile" 259string(0) "" 260string(5) "afile" 261array(3) { 262 ["dirname"]=> 263 string(8) "c://test" 264 ["basename"]=> 265 string(5) "afile" 266 ["filename"]=> 267 string(5) "afile" 268} 269-- Iteration 16 -- 270string(1) "." 271string(14) "c:\test\afile\" 272string(0) "" 273string(14) "c:\test\afile\" 274array(3) { 275 ["dirname"]=> 276 string(1) "." 277 ["basename"]=> 278 string(14) "c:\test\afile\" 279 ["filename"]=> 280 string(14) "c:\test\afile\" 281} 282-- Iteration 17 -- 283string(1) "." 284string(16) "c:\test\prog.exe" 285string(3) "exe" 286string(12) "c:\test\prog" 287array(4) { 288 ["dirname"]=> 289 string(1) "." 290 ["basename"]=> 291 string(16) "c:\test\prog.exe" 292 ["extension"]=> 293 string(3) "exe" 294 ["filename"]=> 295 string(12) "c:\test\prog" 296} 297-- Iteration 18 -- 298string(1) "." 299string(16) "c:\test\prog.exe" 300string(3) "exe" 301string(12) "c:\test\prog" 302array(4) { 303 ["dirname"]=> 304 string(1) "." 305 ["basename"]=> 306 string(16) "c:\test\prog.exe" 307 ["extension"]=> 308 string(3) "exe" 309 ["filename"]=> 310 string(12) "c:\test\prog" 311} 312-- Iteration 19 -- 313string(7) "c:/test" 314string(8) "prog.exe" 315string(3) "exe" 316string(4) "prog" 317array(4) { 318 ["dirname"]=> 319 string(7) "c:/test" 320 ["basename"]=> 321 string(8) "prog.exe" 322 ["extension"]=> 323 string(3) "exe" 324 ["filename"]=> 325 string(4) "prog" 326} 327-- Iteration 20 -- 328string(17) "/usr/include/arpa" 329string(6) "inet.h" 330string(1) "h" 331string(4) "inet" 332array(4) { 333 ["dirname"]=> 334 string(17) "/usr/include/arpa" 335 ["basename"]=> 336 string(6) "inet.h" 337 ["extension"]=> 338 string(1) "h" 339 ["filename"]=> 340 string(4) "inet" 341} 342-- Iteration 21 -- 343string(19) "//usr/include//arpa" 344string(6) "inet.h" 345string(1) "h" 346string(4) "inet" 347array(4) { 348 ["dirname"]=> 349 string(19) "//usr/include//arpa" 350 ["basename"]=> 351 string(6) "inet.h" 352 ["extension"]=> 353 string(1) "h" 354 ["filename"]=> 355 string(4) "inet" 356} 357-- Iteration 22 -- 358string(1) "." 359string(1) "\" 360string(0) "" 361string(1) "\" 362array(3) { 363 ["dirname"]=> 364 string(1) "." 365 ["basename"]=> 366 string(1) "\" 367 ["filename"]=> 368 string(1) "\" 369} 370-- Iteration 23 -- 371string(1) "." 372string(2) "\\" 373string(0) "" 374string(2) "\\" 375array(3) { 376 ["dirname"]=> 377 string(1) "." 378 ["basename"]=> 379 string(2) "\\" 380 ["filename"]=> 381 string(2) "\\" 382} 383-- Iteration 24 -- 384string(1) "/" 385string(0) "" 386string(0) "" 387string(0) "" 388array(3) { 389 ["dirname"]=> 390 string(1) "/" 391 ["basename"]=> 392 string(0) "" 393 ["filename"]=> 394 string(0) "" 395} 396-- Iteration 25 -- 397string(1) "/" 398string(0) "" 399string(0) "" 400string(0) "" 401array(3) { 402 ["dirname"]=> 403 string(1) "/" 404 ["basename"]=> 405 string(0) "" 406 ["filename"]=> 407 string(0) "" 408} 409-- Iteration 26 -- 410string(1) "/" 411string(0) "" 412string(0) "" 413string(0) "" 414array(3) { 415 ["dirname"]=> 416 string(1) "/" 417 ["basename"]=> 418 string(0) "" 419 ["filename"]=> 420 string(0) "" 421} 422-- Iteration 27 -- 423string(17) "/usr/include/arpa" 424string(6) "inet.h" 425string(1) "h" 426string(4) "inet" 427array(4) { 428 ["dirname"]=> 429 string(17) "/usr/include/arpa" 430 ["basename"]=> 431 string(6) "inet.h" 432 ["extension"]=> 433 string(1) "h" 434 ["filename"]=> 435 string(4) "inet" 436} 437-- Iteration 28 -- 438string(27) "c:\windows/system32\drivers" 439string(9) "etc\hosts" 440string(0) "" 441string(9) "etc\hosts" 442array(3) { 443 ["dirname"]=> 444 string(27) "c:\windows/system32\drivers" 445 ["basename"]=> 446 string(9) "etc\hosts" 447 ["filename"]=> 448 string(9) "etc\hosts" 449} 450-- Iteration 29 -- 451string(12) "/usr\include" 452string(11) "arpa\inet.h" 453string(1) "h" 454string(9) "arpa\inet" 455array(4) { 456 ["dirname"]=> 457 string(12) "/usr\include" 458 ["basename"]=> 459 string(11) "arpa\inet.h" 460 ["extension"]=> 461 string(1) "h" 462 ["filename"]=> 463 string(9) "arpa\inet" 464} 465-- Iteration 30 -- 466string(1) "." 467string(25) " c:\test\adir\afile.txt" 468string(3) "txt" 469string(21) " c:\test\adir\afile" 470array(4) { 471 ["dirname"]=> 472 string(1) "." 473 ["basename"]=> 474 string(25) " c:\test\adir\afile.txt" 475 ["extension"]=> 476 string(3) "txt" 477 ["filename"]=> 478 string(21) " c:\test\adir\afile" 479} 480-- Iteration 31 -- 481string(1) "." 482string(25) "c:\test\adir\afile.txt " 483string(6) "txt " 484string(18) "c:\test\adir\afile" 485array(4) { 486 ["dirname"]=> 487 string(1) "." 488 ["basename"]=> 489 string(25) "c:\test\adir\afile.txt " 490 ["extension"]=> 491 string(6) "txt " 492 ["filename"]=> 493 string(18) "c:\test\adir\afile" 494} 495-- Iteration 32 -- 496string(1) "." 497string(28) " c:\test\adir\afile.txt " 498string(6) "txt " 499string(21) " c:\test\adir\afile" 500array(4) { 501 ["dirname"]=> 502 string(1) "." 503 ["basename"]=> 504 string(28) " c:\test\adir\afile.txt " 505 ["extension"]=> 506 string(6) "txt " 507 ["filename"]=> 508 string(21) " c:\test\adir\afile" 509} 510-- Iteration 33 -- 511string(20) " /usr/include/arpa" 512string(6) "inet.h" 513string(1) "h" 514string(4) "inet" 515array(4) { 516 ["dirname"]=> 517 string(20) " /usr/include/arpa" 518 ["basename"]=> 519 string(6) "inet.h" 520 ["extension"]=> 521 string(1) "h" 522 ["filename"]=> 523 string(4) "inet" 524} 525-- Iteration 34 -- 526string(17) "/usr/include/arpa" 527string(9) "inet.h " 528string(4) "h " 529string(4) "inet" 530array(4) { 531 ["dirname"]=> 532 string(17) "/usr/include/arpa" 533 ["basename"]=> 534 string(9) "inet.h " 535 ["extension"]=> 536 string(4) "h " 537 ["filename"]=> 538 string(4) "inet" 539} 540-- Iteration 35 -- 541string(20) " /usr/include/arpa" 542string(9) "inet.h " 543string(4) "h " 544string(4) "inet" 545array(4) { 546 ["dirname"]=> 547 string(20) " /usr/include/arpa" 548 ["basename"]=> 549 string(9) "inet.h " 550 ["extension"]=> 551 string(4) "h " 552 ["filename"]=> 553 string(4) "inet" 554} 555-- Iteration 36 -- 556string(1) "." 557string(3) " c:" 558string(0) "" 559string(3) " c:" 560array(3) { 561 ["dirname"]=> 562 string(1) "." 563 ["basename"]=> 564 string(3) " c:" 565 ["filename"]=> 566 string(3) " c:" 567} 568-- Iteration 37 -- 569string(1) "." 570string(24) " c:\test\adir\afile.txt" 571string(3) "txt" 572string(20) " c:\test\adir\afile" 573array(4) { 574 ["dirname"]=> 575 string(1) "." 576 ["basename"]=> 577 string(24) " c:\test\adir\afile.txt" 578 ["extension"]=> 579 string(3) "txt" 580 ["filename"]=> 581 string(20) " c:\test\adir\afile" 582} 583-- Iteration 38 -- 584string(1) "/" 585string(3) "usr" 586string(0) "" 587string(3) "usr" 588array(3) { 589 ["dirname"]=> 590 string(1) "/" 591 ["basename"]=> 592 string(3) "usr" 593 ["filename"]=> 594 string(3) "usr" 595} 596-- Iteration 39 -- 597string(1) "/" 598string(3) "usr" 599string(0) "" 600string(3) "usr" 601array(3) { 602 ["dirname"]=> 603 string(1) "/" 604 ["basename"]=> 605 string(3) "usr" 606 ["filename"]=> 607 string(3) "usr" 608} 609Done 610