pathinfo_basic.phpt 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. --TEST--
  2. Test pathinfo() function: basic functionality
  3. --FILE--
  4. <?php
  5. /* Prototype: mixed pathinfo ( string $path [, int $options] );
  6. Description: Returns information about a file path
  7. */
  8. echo "*** Testing basic functions of pathinfo() ***\n";
  9. $file_path = dirname(__FILE__);
  10. $paths = array (
  11. /* Testing basic file notation */
  12. "$file_path/foo/symlink.link",
  13. "www.example.co.in",
  14. "/var/www/html/example.html",
  15. "/dir/test.tar.gz",
  16. /* Testing a file with trailing slash */
  17. "$file_path/foo/symlink.link/",
  18. /* Testing file with double slashes */
  19. "$file_path/foo//symlink.link",
  20. "$file_path/foo//symlink.link",
  21. "$file_path/foo//symlink.link//",
  22. /* Testing file with trailing double slashes */
  23. "$file_path/foo/symlink.link//",
  24. /* Testing Binary safe files */
  25. "$file_path/foo".chr(47)."symlink.link",
  26. "$file_path".chr(47)."foo/symlink.link",
  27. "$file_path".chr(47)."foo".chr(47)."symlink.link",
  28. b"$file_path/foo/symlink.link",
  29. /* Testing directories */
  30. ".", // current directory
  31. "$file_path/foo/",
  32. "$file_path/foo//",
  33. "$file_path/../foo/",
  34. "../foo/bar",
  35. "./foo/bar",
  36. "//foo//bar//",
  37. /* Testing with homedir notation */
  38. "~/PHP/php5.2.0/",
  39. /* Testing normal directory notation */
  40. "/home/example/test/",
  41. "http://httpd.apache.org/core.html#acceptpathinfo"
  42. );
  43. $counter = 1;
  44. /* loop through $paths to test each $path in the above array */
  45. foreach($paths as $path) {
  46. echo "-- Iteration $counter --\n";
  47. var_dump( pathinfo($path, PATHINFO_DIRNAME) );
  48. var_dump( pathinfo($path, PATHINFO_BASENAME) );
  49. var_dump( pathinfo($path, PATHINFO_EXTENSION) );
  50. var_dump( pathinfo($path, PATHINFO_FILENAME) );
  51. var_dump( pathinfo($path) );
  52. $counter++;
  53. }
  54. echo "Done\n";
  55. ?>
  56. --EXPECTF--
  57. *** Testing basic functions of pathinfo() ***
  58. -- Iteration 1 --
  59. %unicode|string%(%d) "%s/foo"
  60. %unicode|string%(12) "symlink.link"
  61. %unicode|string%(4) "link"
  62. %unicode|string%(7) "symlink"
  63. array(4) {
  64. [%u|b%"dirname"]=>
  65. %unicode|string%(%d) "%s/foo"
  66. [%u|b%"basename"]=>
  67. %unicode|string%(12) "symlink.link"
  68. [%u|b%"extension"]=>
  69. %unicode|string%(4) "link"
  70. [%u|b%"filename"]=>
  71. %unicode|string%(7) "symlink"
  72. }
  73. -- Iteration 2 --
  74. %unicode|string%(1) "."
  75. %unicode|string%(17) "www.example.co.in"
  76. %unicode|string%(2) "in"
  77. %unicode|string%(14) "www.example.co"
  78. array(4) {
  79. [%u|b%"dirname"]=>
  80. %unicode|string%(1) "."
  81. [%u|b%"basename"]=>
  82. %unicode|string%(17) "www.example.co.in"
  83. [%u|b%"extension"]=>
  84. %unicode|string%(2) "in"
  85. [%u|b%"filename"]=>
  86. %unicode|string%(14) "www.example.co"
  87. }
  88. -- Iteration 3 --
  89. %unicode|string%(13) "/var/www/html"
  90. %unicode|string%(12) "example.html"
  91. %unicode|string%(4) "html"
  92. %unicode|string%(7) "example"
  93. array(4) {
  94. [%u|b%"dirname"]=>
  95. %unicode|string%(13) "/var/www/html"
  96. [%u|b%"basename"]=>
  97. %unicode|string%(12) "example.html"
  98. [%u|b%"extension"]=>
  99. %unicode|string%(4) "html"
  100. [%u|b%"filename"]=>
  101. %unicode|string%(7) "example"
  102. }
  103. -- Iteration 4 --
  104. %unicode|string%(4) "/dir"
  105. %unicode|string%(11) "test.tar.gz"
  106. %unicode|string%(2) "gz"
  107. %unicode|string%(8) "test.tar"
  108. array(4) {
  109. [%u|b%"dirname"]=>
  110. %unicode|string%(4) "/dir"
  111. [%u|b%"basename"]=>
  112. %unicode|string%(11) "test.tar.gz"
  113. [%u|b%"extension"]=>
  114. %unicode|string%(2) "gz"
  115. [%u|b%"filename"]=>
  116. %unicode|string%(8) "test.tar"
  117. }
  118. -- Iteration 5 --
  119. %unicode|string%(%d) "%s/foo"
  120. %unicode|string%(12) "symlink.link"
  121. %unicode|string%(4) "link"
  122. %unicode|string%(7) "symlink"
  123. array(4) {
  124. [%u|b%"dirname"]=>
  125. %unicode|string%(%d) "%s/foo"
  126. [%u|b%"basename"]=>
  127. %unicode|string%(12) "symlink.link"
  128. [%u|b%"extension"]=>
  129. %unicode|string%(4) "link"
  130. [%u|b%"filename"]=>
  131. %unicode|string%(7) "symlink"
  132. }
  133. -- Iteration 6 --
  134. %unicode|string%(%d) "%s/foo"
  135. %unicode|string%(12) "symlink.link"
  136. %unicode|string%(4) "link"
  137. %unicode|string%(7) "symlink"
  138. array(4) {
  139. [%u|b%"dirname"]=>
  140. %unicode|string%(%d) "%s/foo"
  141. [%u|b%"basename"]=>
  142. %unicode|string%(12) "symlink.link"
  143. [%u|b%"extension"]=>
  144. %unicode|string%(4) "link"
  145. [%u|b%"filename"]=>
  146. %unicode|string%(7) "symlink"
  147. }
  148. -- Iteration 7 --
  149. %unicode|string%(%d) "%s/foo"
  150. %unicode|string%(12) "symlink.link"
  151. %unicode|string%(4) "link"
  152. %unicode|string%(7) "symlink"
  153. array(4) {
  154. [%u|b%"dirname"]=>
  155. %unicode|string%(%d) "%s/foo"
  156. [%u|b%"basename"]=>
  157. %unicode|string%(12) "symlink.link"
  158. [%u|b%"extension"]=>
  159. %unicode|string%(4) "link"
  160. [%u|b%"filename"]=>
  161. %unicode|string%(7) "symlink"
  162. }
  163. -- Iteration 8 --
  164. %unicode|string%(%d) "%s/foo"
  165. %unicode|string%(12) "symlink.link"
  166. %unicode|string%(4) "link"
  167. %unicode|string%(7) "symlink"
  168. array(4) {
  169. [%u|b%"dirname"]=>
  170. %unicode|string%(%d) "%s/foo"
  171. [%u|b%"basename"]=>
  172. %unicode|string%(12) "symlink.link"
  173. [%u|b%"extension"]=>
  174. %unicode|string%(4) "link"
  175. [%u|b%"filename"]=>
  176. %unicode|string%(7) "symlink"
  177. }
  178. -- Iteration 9 --
  179. %unicode|string%(%d) "%s/foo"
  180. %unicode|string%(12) "symlink.link"
  181. %unicode|string%(4) "link"
  182. %unicode|string%(7) "symlink"
  183. array(4) {
  184. [%u|b%"dirname"]=>
  185. %unicode|string%(%d) "%s/foo"
  186. [%u|b%"basename"]=>
  187. %unicode|string%(12) "symlink.link"
  188. [%u|b%"extension"]=>
  189. %unicode|string%(4) "link"
  190. [%u|b%"filename"]=>
  191. %unicode|string%(7) "symlink"
  192. }
  193. -- Iteration 10 --
  194. %unicode|string%(%d) "%s/foo"
  195. %unicode|string%(12) "symlink.link"
  196. %unicode|string%(4) "link"
  197. %unicode|string%(7) "symlink"
  198. array(4) {
  199. [%u|b%"dirname"]=>
  200. %unicode|string%(%d) "%s/foo"
  201. [%u|b%"basename"]=>
  202. %unicode|string%(12) "symlink.link"
  203. [%u|b%"extension"]=>
  204. %unicode|string%(4) "link"
  205. [%u|b%"filename"]=>
  206. %unicode|string%(7) "symlink"
  207. }
  208. -- Iteration 11 --
  209. %unicode|string%(%d) "%s/foo"
  210. %unicode|string%(12) "symlink.link"
  211. %unicode|string%(4) "link"
  212. %unicode|string%(7) "symlink"
  213. array(4) {
  214. [%u|b%"dirname"]=>
  215. %unicode|string%(%d) "%s/foo"
  216. [%u|b%"basename"]=>
  217. %unicode|string%(12) "symlink.link"
  218. [%u|b%"extension"]=>
  219. %unicode|string%(4) "link"
  220. [%u|b%"filename"]=>
  221. %unicode|string%(7) "symlink"
  222. }
  223. -- Iteration 12 --
  224. %unicode|string%(%d) "%s/foo"
  225. %unicode|string%(12) "symlink.link"
  226. %unicode|string%(4) "link"
  227. %unicode|string%(7) "symlink"
  228. array(4) {
  229. [%u|b%"dirname"]=>
  230. %unicode|string%(%d) "%s/foo"
  231. [%u|b%"basename"]=>
  232. %unicode|string%(12) "symlink.link"
  233. [%u|b%"extension"]=>
  234. %unicode|string%(4) "link"
  235. [%u|b%"filename"]=>
  236. %unicode|string%(7) "symlink"
  237. }
  238. -- Iteration 13 --
  239. string(%d) "%s/foo"
  240. string(12) "symlink.link"
  241. string(4) "link"
  242. string(7) "symlink"
  243. array(4) {
  244. [%u|b%"dirname"]=>
  245. string(%d) "%s/foo"
  246. [%u|b%"basename"]=>
  247. string(12) "symlink.link"
  248. [%u|b%"extension"]=>
  249. string(4) "link"
  250. [%u|b%"filename"]=>
  251. string(7) "symlink"
  252. }
  253. -- Iteration 14 --
  254. %unicode|string%(1) "."
  255. %unicode|string%(1) "."
  256. %unicode|string%(0) ""
  257. %unicode|string%(0) ""
  258. array(4) {
  259. [%u|b%"dirname"]=>
  260. %unicode|string%(1) "."
  261. [%u|b%"basename"]=>
  262. %unicode|string%(1) "."
  263. [%u|b%"extension"]=>
  264. %unicode|string%(0) ""
  265. [%u|b%"filename"]=>
  266. %unicode|string%(0) ""
  267. }
  268. -- Iteration 15 --
  269. %unicode|string%(%d) "%s"
  270. %unicode|string%(3) "foo"
  271. %unicode|string%(0) ""
  272. %unicode|string%(3) "foo"
  273. array(3) {
  274. [%u|b%"dirname"]=>
  275. %unicode|string%(%d) "%s"
  276. [%u|b%"basename"]=>
  277. %unicode|string%(3) "foo"
  278. [%u|b%"filename"]=>
  279. %unicode|string%(3) "foo"
  280. }
  281. -- Iteration 16 --
  282. %unicode|string%(%d) "%s"
  283. %unicode|string%(3) "foo"
  284. %unicode|string%(0) ""
  285. %unicode|string%(3) "foo"
  286. array(3) {
  287. [%u|b%"dirname"]=>
  288. %unicode|string%(%d) "%s"
  289. [%u|b%"basename"]=>
  290. %unicode|string%(3) "foo"
  291. [%u|b%"filename"]=>
  292. %unicode|string%(3) "foo"
  293. }
  294. -- Iteration 17 --
  295. %unicode|string%(%d) "%s/.."
  296. %unicode|string%(3) "foo"
  297. %unicode|string%(0) ""
  298. %unicode|string%(3) "foo"
  299. array(3) {
  300. [%u|b%"dirname"]=>
  301. %unicode|string%(%d) "%s/.."
  302. [%u|b%"basename"]=>
  303. %unicode|string%(3) "foo"
  304. [%u|b%"filename"]=>
  305. %unicode|string%(3) "foo"
  306. }
  307. -- Iteration 18 --
  308. %unicode|string%(6) "../foo"
  309. %unicode|string%(3) "bar"
  310. %unicode|string%(0) ""
  311. %unicode|string%(3) "bar"
  312. array(3) {
  313. [%u|b%"dirname"]=>
  314. %unicode|string%(6) "../foo"
  315. [%u|b%"basename"]=>
  316. %unicode|string%(3) "bar"
  317. [%u|b%"filename"]=>
  318. %unicode|string%(3) "bar"
  319. }
  320. -- Iteration 19 --
  321. %unicode|string%(5) "./foo"
  322. %unicode|string%(3) "bar"
  323. %unicode|string%(0) ""
  324. %unicode|string%(3) "bar"
  325. array(3) {
  326. [%u|b%"dirname"]=>
  327. %unicode|string%(5) "./foo"
  328. [%u|b%"basename"]=>
  329. %unicode|string%(3) "bar"
  330. [%u|b%"filename"]=>
  331. %unicode|string%(3) "bar"
  332. }
  333. -- Iteration 20 --
  334. %unicode|string%(5) "//foo"
  335. %unicode|string%(3) "bar"
  336. %unicode|string%(0) ""
  337. %unicode|string%(3) "bar"
  338. array(3) {
  339. [%u|b%"dirname"]=>
  340. %unicode|string%(5) "//foo"
  341. [%u|b%"basename"]=>
  342. %unicode|string%(3) "bar"
  343. [%u|b%"filename"]=>
  344. %unicode|string%(3) "bar"
  345. }
  346. -- Iteration 21 --
  347. %unicode|string%(5) "~/PHP"
  348. %unicode|string%(8) "php5.2.0"
  349. %unicode|string%(1) "0"
  350. %unicode|string%(6) "php5.2"
  351. array(4) {
  352. [%u|b%"dirname"]=>
  353. %unicode|string%(5) "~/PHP"
  354. [%u|b%"basename"]=>
  355. %unicode|string%(8) "php5.2.0"
  356. [%u|b%"extension"]=>
  357. %unicode|string%(1) "0"
  358. [%u|b%"filename"]=>
  359. %unicode|string%(6) "php5.2"
  360. }
  361. -- Iteration 22 --
  362. %unicode|string%(13) "/home/example"
  363. %unicode|string%(4) "test"
  364. %unicode|string%(0) ""
  365. %unicode|string%(4) "test"
  366. array(3) {
  367. [%u|b%"dirname"]=>
  368. %unicode|string%(13) "/home/example"
  369. [%u|b%"basename"]=>
  370. %unicode|string%(4) "test"
  371. [%u|b%"filename"]=>
  372. %unicode|string%(4) "test"
  373. }
  374. -- Iteration 23 --
  375. %unicode|string%(23) "http://httpd.apache.org"
  376. %unicode|string%(24) "core.html#acceptpathinfo"
  377. %unicode|string%(19) "html#acceptpathinfo"
  378. %unicode|string%(4) "core"
  379. array(4) {
  380. [%u|b%"dirname"]=>
  381. %unicode|string%(23) "http://httpd.apache.org"
  382. [%u|b%"basename"]=>
  383. %unicode|string%(24) "core.html#acceptpathinfo"
  384. [%u|b%"extension"]=>
  385. %unicode|string%(19) "html#acceptpathinfo"
  386. [%u|b%"filename"]=>
  387. %unicode|string%(4) "core"
  388. }
  389. Done