pathinfo_variaton.phpt 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. --TEST--
  2. Test pathinfo() function: usage variations
  3. --FILE--
  4. <?php
  5. echo "*** Testing pathinfo() with miscellaneous input arguments ***\n";
  6. class object_temp {
  7. public $url_var = "www.foo.com";
  8. var $html_var = "/var/html/testdir/example.html";
  9. var $dir_var = "/testdir/foo/test/";
  10. public $file_var = "/foo//symlink.link";
  11. var $number = 12345;
  12. }
  13. $obj = new object_temp();
  14. $path_arr = array (
  15. "www.example.com",
  16. "/testdir/foo//test/",
  17. "../foo/test.link",
  18. "./test/work/scratch/mydir/yourdir/ourdir/test1/test2/test3/test4/test5/test6/test.tmp",
  19. 2.345
  20. );
  21. $paths = array (
  22. /* pathname containing numeric string */
  23. 0,
  24. 1234,
  25. -1234,
  26. 2.3456,
  27. /* pathname as boolean */
  28. TRUE,
  29. FALSE,
  30. /* pathname as an array */
  31. "./array(1, 2)",
  32. "array( array(), null)",
  33. /* pathname as spaces */
  34. " ",
  35. ' ',
  36. /* empty pathname */
  37. "",
  38. '',
  39. /* pathname as members of object */
  40. $obj->url_var,
  41. $obj->html_var,
  42. $obj->dir_var,
  43. $obj->file_var,
  44. $obj->number,
  45. /* pathname as member of array */
  46. $path_arr[0],
  47. $path_arr[1],
  48. $path_arr[2],
  49. $path_arr[3],
  50. $path_arr[4]
  51. );
  52. $counter = 1;
  53. /* loop through $paths to test each $path in the above array */
  54. foreach($paths as $path) {
  55. echo "-- Iteration $counter --\n";
  56. var_dump( pathinfo($path) );
  57. var_dump( pathinfo($path, PATHINFO_DIRNAME) );
  58. var_dump( pathinfo($path, PATHINFO_BASENAME) );
  59. var_dump( pathinfo($path, PATHINFO_EXTENSION) );
  60. var_dump( pathinfo($path, PATHINFO_FILENAME) );
  61. $counter++;
  62. }
  63. echo "Done\n";
  64. ?>
  65. --EXPECT--
  66. *** Testing pathinfo() with miscellaneous input arguments ***
  67. -- Iteration 1 --
  68. array(3) {
  69. ["dirname"]=>
  70. string(1) "."
  71. ["basename"]=>
  72. string(1) "0"
  73. ["filename"]=>
  74. string(1) "0"
  75. }
  76. string(1) "."
  77. string(1) "0"
  78. string(0) ""
  79. string(1) "0"
  80. -- Iteration 2 --
  81. array(3) {
  82. ["dirname"]=>
  83. string(1) "."
  84. ["basename"]=>
  85. string(4) "1234"
  86. ["filename"]=>
  87. string(4) "1234"
  88. }
  89. string(1) "."
  90. string(4) "1234"
  91. string(0) ""
  92. string(4) "1234"
  93. -- Iteration 3 --
  94. array(3) {
  95. ["dirname"]=>
  96. string(1) "."
  97. ["basename"]=>
  98. string(5) "-1234"
  99. ["filename"]=>
  100. string(5) "-1234"
  101. }
  102. string(1) "."
  103. string(5) "-1234"
  104. string(0) ""
  105. string(5) "-1234"
  106. -- Iteration 4 --
  107. array(4) {
  108. ["dirname"]=>
  109. string(1) "."
  110. ["basename"]=>
  111. string(6) "2.3456"
  112. ["extension"]=>
  113. string(4) "3456"
  114. ["filename"]=>
  115. string(1) "2"
  116. }
  117. string(1) "."
  118. string(6) "2.3456"
  119. string(4) "3456"
  120. string(1) "2"
  121. -- Iteration 5 --
  122. array(3) {
  123. ["dirname"]=>
  124. string(1) "."
  125. ["basename"]=>
  126. string(1) "1"
  127. ["filename"]=>
  128. string(1) "1"
  129. }
  130. string(1) "."
  131. string(1) "1"
  132. string(0) ""
  133. string(1) "1"
  134. -- Iteration 6 --
  135. array(2) {
  136. ["basename"]=>
  137. string(0) ""
  138. ["filename"]=>
  139. string(0) ""
  140. }
  141. string(0) ""
  142. string(0) ""
  143. string(0) ""
  144. string(0) ""
  145. -- Iteration 7 --
  146. array(3) {
  147. ["dirname"]=>
  148. string(1) "."
  149. ["basename"]=>
  150. string(11) "array(1, 2)"
  151. ["filename"]=>
  152. string(11) "array(1, 2)"
  153. }
  154. string(1) "."
  155. string(11) "array(1, 2)"
  156. string(0) ""
  157. string(11) "array(1, 2)"
  158. -- Iteration 8 --
  159. array(3) {
  160. ["dirname"]=>
  161. string(1) "."
  162. ["basename"]=>
  163. string(21) "array( array(), null)"
  164. ["filename"]=>
  165. string(21) "array( array(), null)"
  166. }
  167. string(1) "."
  168. string(21) "array( array(), null)"
  169. string(0) ""
  170. string(21) "array( array(), null)"
  171. -- Iteration 9 --
  172. array(3) {
  173. ["dirname"]=>
  174. string(1) "."
  175. ["basename"]=>
  176. string(1) " "
  177. ["filename"]=>
  178. string(1) " "
  179. }
  180. string(1) "."
  181. string(1) " "
  182. string(0) ""
  183. string(1) " "
  184. -- Iteration 10 --
  185. array(3) {
  186. ["dirname"]=>
  187. string(1) "."
  188. ["basename"]=>
  189. string(1) " "
  190. ["filename"]=>
  191. string(1) " "
  192. }
  193. string(1) "."
  194. string(1) " "
  195. string(0) ""
  196. string(1) " "
  197. -- Iteration 11 --
  198. array(2) {
  199. ["basename"]=>
  200. string(0) ""
  201. ["filename"]=>
  202. string(0) ""
  203. }
  204. string(0) ""
  205. string(0) ""
  206. string(0) ""
  207. string(0) ""
  208. -- Iteration 12 --
  209. array(2) {
  210. ["basename"]=>
  211. string(0) ""
  212. ["filename"]=>
  213. string(0) ""
  214. }
  215. string(0) ""
  216. string(0) ""
  217. string(0) ""
  218. string(0) ""
  219. -- Iteration 13 --
  220. array(4) {
  221. ["dirname"]=>
  222. string(1) "."
  223. ["basename"]=>
  224. string(11) "www.foo.com"
  225. ["extension"]=>
  226. string(3) "com"
  227. ["filename"]=>
  228. string(7) "www.foo"
  229. }
  230. string(1) "."
  231. string(11) "www.foo.com"
  232. string(3) "com"
  233. string(7) "www.foo"
  234. -- Iteration 14 --
  235. array(4) {
  236. ["dirname"]=>
  237. string(17) "/var/html/testdir"
  238. ["basename"]=>
  239. string(12) "example.html"
  240. ["extension"]=>
  241. string(4) "html"
  242. ["filename"]=>
  243. string(7) "example"
  244. }
  245. string(17) "/var/html/testdir"
  246. string(12) "example.html"
  247. string(4) "html"
  248. string(7) "example"
  249. -- Iteration 15 --
  250. array(3) {
  251. ["dirname"]=>
  252. string(12) "/testdir/foo"
  253. ["basename"]=>
  254. string(4) "test"
  255. ["filename"]=>
  256. string(4) "test"
  257. }
  258. string(12) "/testdir/foo"
  259. string(4) "test"
  260. string(0) ""
  261. string(4) "test"
  262. -- Iteration 16 --
  263. array(4) {
  264. ["dirname"]=>
  265. string(4) "/foo"
  266. ["basename"]=>
  267. string(12) "symlink.link"
  268. ["extension"]=>
  269. string(4) "link"
  270. ["filename"]=>
  271. string(7) "symlink"
  272. }
  273. string(4) "/foo"
  274. string(12) "symlink.link"
  275. string(4) "link"
  276. string(7) "symlink"
  277. -- Iteration 17 --
  278. array(3) {
  279. ["dirname"]=>
  280. string(1) "."
  281. ["basename"]=>
  282. string(5) "12345"
  283. ["filename"]=>
  284. string(5) "12345"
  285. }
  286. string(1) "."
  287. string(5) "12345"
  288. string(0) ""
  289. string(5) "12345"
  290. -- Iteration 18 --
  291. array(4) {
  292. ["dirname"]=>
  293. string(1) "."
  294. ["basename"]=>
  295. string(15) "www.example.com"
  296. ["extension"]=>
  297. string(3) "com"
  298. ["filename"]=>
  299. string(11) "www.example"
  300. }
  301. string(1) "."
  302. string(15) "www.example.com"
  303. string(3) "com"
  304. string(11) "www.example"
  305. -- Iteration 19 --
  306. array(3) {
  307. ["dirname"]=>
  308. string(12) "/testdir/foo"
  309. ["basename"]=>
  310. string(4) "test"
  311. ["filename"]=>
  312. string(4) "test"
  313. }
  314. string(12) "/testdir/foo"
  315. string(4) "test"
  316. string(0) ""
  317. string(4) "test"
  318. -- Iteration 20 --
  319. array(4) {
  320. ["dirname"]=>
  321. string(6) "../foo"
  322. ["basename"]=>
  323. string(9) "test.link"
  324. ["extension"]=>
  325. string(4) "link"
  326. ["filename"]=>
  327. string(4) "test"
  328. }
  329. string(6) "../foo"
  330. string(9) "test.link"
  331. string(4) "link"
  332. string(4) "test"
  333. -- Iteration 21 --
  334. array(4) {
  335. ["dirname"]=>
  336. string(76) "./test/work/scratch/mydir/yourdir/ourdir/test1/test2/test3/test4/test5/test6"
  337. ["basename"]=>
  338. string(8) "test.tmp"
  339. ["extension"]=>
  340. string(3) "tmp"
  341. ["filename"]=>
  342. string(4) "test"
  343. }
  344. string(76) "./test/work/scratch/mydir/yourdir/ourdir/test1/test2/test3/test4/test5/test6"
  345. string(8) "test.tmp"
  346. string(3) "tmp"
  347. string(4) "test"
  348. -- Iteration 22 --
  349. array(4) {
  350. ["dirname"]=>
  351. string(1) "."
  352. ["basename"]=>
  353. string(5) "2.345"
  354. ["extension"]=>
  355. string(3) "345"
  356. ["filename"]=>
  357. string(1) "2"
  358. }
  359. string(1) "."
  360. string(5) "2.345"
  361. string(3) "345"
  362. string(1) "2"
  363. Done