basename_variation1.phpt 6.1 KB

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