fscanf_variation53.phpt 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. --TEST--
  2. Test fscanf() function: usage variations - file pointer pointing to EOF
  3. --FILE--
  4. <?php
  5. /* Test fscanf() to read a file when file pointer is pointing to EOF */
  6. $file_path = __DIR__;
  7. echo "*** Test fscanf(): to read a file when file pointer is pointing to EOF ***\n";
  8. // various formats
  9. $formats = array( "%d", "%f", "%e", "%u", " %s", "%x", "%o");
  10. $counter = 1;
  11. // various read modes
  12. $modes = array("r", "rb", "rt", "r+", "r+b", "r+t",
  13. "w+", "w+b", "w+t",
  14. "a+", "a+b", "a+t"
  15. );
  16. $counter = 1;
  17. // reading the values from file using different integer formats
  18. foreach($modes as $mode) {
  19. // create an empty file
  20. $filename = "$file_path/fscanf_variation53.tmp";
  21. $file_handle = fopen($filename, "w");
  22. if($file_handle == false)
  23. exit("Error:failed to open file $filename");
  24. //writing data to the file
  25. @fwrite($file_handle, "Sample text\n");
  26. // writing a blank line
  27. @fwrite($file_handle, "\n");
  28. //closing the file
  29. fclose($file_handle);
  30. // opening file in $mode mode
  31. $file_handle = fopen($filename, $mode);
  32. if($file_handle == false) {
  33. exit("Error:failed to open file $filename");
  34. }
  35. echo "\n-- iteration $counter --\n";
  36. // current location
  37. var_dump( ftell($file_handle) );
  38. // set the file pointer to eof
  39. var_dump( fseek($file_handle, 0, SEEK_END) );
  40. // current location
  41. var_dump( ftell($file_handle) );
  42. foreach($formats as $format) {
  43. var_dump( fscanf($file_handle,$format) );
  44. }
  45. $counter++;
  46. fclose($file_handle);
  47. unlink($filename);
  48. }
  49. echo "\n*** Done ***";
  50. ?>
  51. --CLEAN--
  52. <?php
  53. $file_path = __DIR__;
  54. $filename = "$file_path/fscanf_variation53.tmp";
  55. if(file_exists($filename)) {
  56. unlink($filename);
  57. }
  58. ?>
  59. --EXPECT--
  60. *** Test fscanf(): to read a file when file pointer is pointing to EOF ***
  61. -- iteration 1 --
  62. int(0)
  63. int(0)
  64. int(13)
  65. bool(false)
  66. bool(false)
  67. bool(false)
  68. bool(false)
  69. bool(false)
  70. bool(false)
  71. bool(false)
  72. -- iteration 2 --
  73. int(0)
  74. int(0)
  75. int(13)
  76. bool(false)
  77. bool(false)
  78. bool(false)
  79. bool(false)
  80. bool(false)
  81. bool(false)
  82. bool(false)
  83. -- iteration 3 --
  84. int(0)
  85. int(0)
  86. int(13)
  87. bool(false)
  88. bool(false)
  89. bool(false)
  90. bool(false)
  91. bool(false)
  92. bool(false)
  93. bool(false)
  94. -- iteration 4 --
  95. int(0)
  96. int(0)
  97. int(13)
  98. bool(false)
  99. bool(false)
  100. bool(false)
  101. bool(false)
  102. bool(false)
  103. bool(false)
  104. bool(false)
  105. -- iteration 5 --
  106. int(0)
  107. int(0)
  108. int(13)
  109. bool(false)
  110. bool(false)
  111. bool(false)
  112. bool(false)
  113. bool(false)
  114. bool(false)
  115. bool(false)
  116. -- iteration 6 --
  117. int(0)
  118. int(0)
  119. int(13)
  120. bool(false)
  121. bool(false)
  122. bool(false)
  123. bool(false)
  124. bool(false)
  125. bool(false)
  126. bool(false)
  127. -- iteration 7 --
  128. int(0)
  129. int(0)
  130. int(0)
  131. bool(false)
  132. bool(false)
  133. bool(false)
  134. bool(false)
  135. bool(false)
  136. bool(false)
  137. bool(false)
  138. -- iteration 8 --
  139. int(0)
  140. int(0)
  141. int(0)
  142. bool(false)
  143. bool(false)
  144. bool(false)
  145. bool(false)
  146. bool(false)
  147. bool(false)
  148. bool(false)
  149. -- iteration 9 --
  150. int(0)
  151. int(0)
  152. int(0)
  153. bool(false)
  154. bool(false)
  155. bool(false)
  156. bool(false)
  157. bool(false)
  158. bool(false)
  159. bool(false)
  160. -- iteration 10 --
  161. int(0)
  162. int(0)
  163. int(13)
  164. bool(false)
  165. bool(false)
  166. bool(false)
  167. bool(false)
  168. bool(false)
  169. bool(false)
  170. bool(false)
  171. -- iteration 11 --
  172. int(0)
  173. int(0)
  174. int(13)
  175. bool(false)
  176. bool(false)
  177. bool(false)
  178. bool(false)
  179. bool(false)
  180. bool(false)
  181. bool(false)
  182. -- iteration 12 --
  183. int(0)
  184. int(0)
  185. int(13)
  186. bool(false)
  187. bool(false)
  188. bool(false)
  189. bool(false)
  190. bool(false)
  191. bool(false)
  192. bool(false)
  193. *** Done ***