file_variation9.phpt 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. --TEST--
  2. Test file function : variation - test various endings of a file
  3. --CREDITS--
  4. Dave Kelsey <d_kelsey@uk.ibm.com>
  5. --FILE--
  6. <?php
  7. /* Prototype : array file(string filename [, int flags[, resource context]])
  8. * Description: Read entire file into an array
  9. * Source code: ext/standard/file.c
  10. * Alias to functions:
  11. */
  12. echo "*** Testing file() : variation ***\n";
  13. $testfile = dirname(__FILE__)."/fileVar9.txt";
  14. $contents = array(
  15. "File ends on a single character\na",
  16. "File ends on a new line\n",
  17. "File ends on multiple newlines\n\n\n\n",
  18. "File has\n\nmultiple lines and newlines\n\n",
  19. "File has\r\nmultiple crlfs\n\r\n"
  20. );
  21. @unlink($testfile);
  22. foreach ($contents as $content) {
  23. $h = fopen($testfile, "w");
  24. fwrite($h, $content);
  25. fclose($h);
  26. var_dump(file($testfile));
  27. unlink($testfile);
  28. }
  29. echo "\n*** Done ***\n";
  30. ?>
  31. --EXPECTF--
  32. *** Testing file() : variation ***
  33. array(2) {
  34. [0]=>
  35. string(32) "File ends on a single character
  36. "
  37. [1]=>
  38. string(1) "a"
  39. }
  40. array(1) {
  41. [0]=>
  42. string(24) "File ends on a new line
  43. "
  44. }
  45. array(4) {
  46. [0]=>
  47. string(31) "File ends on multiple newlines
  48. "
  49. [1]=>
  50. string(1) "
  51. "
  52. [2]=>
  53. string(1) "
  54. "
  55. [3]=>
  56. string(1) "
  57. "
  58. }
  59. array(4) {
  60. [0]=>
  61. string(9) "File has
  62. "
  63. [1]=>
  64. string(1) "
  65. "
  66. [2]=>
  67. string(28) "multiple lines and newlines
  68. "
  69. [3]=>
  70. string(1) "
  71. "
  72. }
  73. array(3) {
  74. [0]=>
  75. string(10) "File has
  76. "
  77. [1]=>
  78. string(15) "multiple crlfs
  79. "
  80. [2]=>
  81. string(2) "
  82. "
  83. }
  84. *** Done ***