fgetc_variation4.phpt 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. --TEST--
  2. Test fgetc() function : usage variations - different read modes
  3. --FILE--
  4. <?php
  5. /*
  6. Prototype: string fgetc ( resource $handle );
  7. Description: Gets character from file pointer
  8. */
  9. /* read from fie using fgetc, file opened using different
  10. read read modes */
  11. echo "*** Testing fgetc() : usage variations ***\n";
  12. echo "-- Testing fgetc() with files opened with different read modes --\n";
  13. $file_modes = array( "a+", "a+b", "a+t",
  14. "x+", "x+b", "x+t",
  15. "w+", "w+b", "w+t" );
  16. $filename = dirname(__FILE__)."/fgetc_variation4.tmp";
  17. foreach ($file_modes as $file_mode ) {
  18. echo "-- File opened in mode : $file_mode --\n";
  19. $file_handle = fopen($filename, $file_mode);
  20. if(!$file_handle) {
  21. echo "Error: failed to open file $filename!\n";
  22. exit();
  23. }
  24. $data = "fgetc\n test";
  25. fwrite($file_handle, $data);
  26. // rewind the file pointer to beginning of the file
  27. var_dump( rewind($file_handle) );
  28. var_dump( ftell($file_handle) );
  29. var_dump( feof($file_handle) );
  30. // read from file, at least 7 chars
  31. for($counter =0; $counter < 7; $counter ++) {
  32. var_dump( fgetc($file_handle) ); // expected : 1 char
  33. var_dump( ftell($file_handle) );
  34. var_dump( feof($file_handle) ); // check if end of file pointer is set
  35. }
  36. // close the file
  37. fclose($file_handle);
  38. // delete the file
  39. unlink($filename);
  40. }
  41. echo "Done\n";
  42. ?>
  43. --EXPECTF--
  44. *** Testing fgetc() : usage variations ***
  45. -- Testing fgetc() with files opened with different read modes --
  46. -- File opened in mode : a+ --
  47. bool(true)
  48. int(0)
  49. bool(false)
  50. string(1) "f"
  51. int(1)
  52. bool(false)
  53. string(1) "g"
  54. int(2)
  55. bool(false)
  56. string(1) "e"
  57. int(3)
  58. bool(false)
  59. string(1) "t"
  60. int(4)
  61. bool(false)
  62. string(1) "c"
  63. int(5)
  64. bool(false)
  65. string(1) "
  66. "
  67. int(6)
  68. bool(false)
  69. string(1) " "
  70. int(7)
  71. bool(false)
  72. -- File opened in mode : a+b --
  73. bool(true)
  74. int(0)
  75. bool(false)
  76. string(1) "f"
  77. int(1)
  78. bool(false)
  79. string(1) "g"
  80. int(2)
  81. bool(false)
  82. string(1) "e"
  83. int(3)
  84. bool(false)
  85. string(1) "t"
  86. int(4)
  87. bool(false)
  88. string(1) "c"
  89. int(5)
  90. bool(false)
  91. string(1) "
  92. "
  93. int(6)
  94. bool(false)
  95. string(1) " "
  96. int(7)
  97. bool(false)
  98. -- File opened in mode : a+t --
  99. bool(true)
  100. int(0)
  101. bool(false)
  102. string(1) "f"
  103. int(1)
  104. bool(false)
  105. string(1) "g"
  106. int(2)
  107. bool(false)
  108. string(1) "e"
  109. int(3)
  110. bool(false)
  111. string(1) "t"
  112. int(4)
  113. bool(false)
  114. string(1) "c"
  115. int(5)
  116. bool(false)
  117. string(1) "
  118. "
  119. int(6)
  120. bool(false)
  121. string(1) " "
  122. int(7)
  123. bool(false)
  124. -- File opened in mode : x+ --
  125. bool(true)
  126. int(0)
  127. bool(false)
  128. string(1) "f"
  129. int(1)
  130. bool(false)
  131. string(1) "g"
  132. int(2)
  133. bool(false)
  134. string(1) "e"
  135. int(3)
  136. bool(false)
  137. string(1) "t"
  138. int(4)
  139. bool(false)
  140. string(1) "c"
  141. int(5)
  142. bool(false)
  143. string(1) "
  144. "
  145. int(6)
  146. bool(false)
  147. string(1) " "
  148. int(7)
  149. bool(false)
  150. -- File opened in mode : x+b --
  151. bool(true)
  152. int(0)
  153. bool(false)
  154. string(1) "f"
  155. int(1)
  156. bool(false)
  157. string(1) "g"
  158. int(2)
  159. bool(false)
  160. string(1) "e"
  161. int(3)
  162. bool(false)
  163. string(1) "t"
  164. int(4)
  165. bool(false)
  166. string(1) "c"
  167. int(5)
  168. bool(false)
  169. string(1) "
  170. "
  171. int(6)
  172. bool(false)
  173. string(1) " "
  174. int(7)
  175. bool(false)
  176. -- File opened in mode : x+t --
  177. bool(true)
  178. int(0)
  179. bool(false)
  180. string(1) "f"
  181. int(1)
  182. bool(false)
  183. string(1) "g"
  184. int(2)
  185. bool(false)
  186. string(1) "e"
  187. int(3)
  188. bool(false)
  189. string(1) "t"
  190. int(4)
  191. bool(false)
  192. string(1) "c"
  193. int(5)
  194. bool(false)
  195. string(1) "
  196. "
  197. int(6)
  198. bool(false)
  199. string(1) " "
  200. int(7)
  201. bool(false)
  202. -- File opened in mode : w+ --
  203. bool(true)
  204. int(0)
  205. bool(false)
  206. string(1) "f"
  207. int(1)
  208. bool(false)
  209. string(1) "g"
  210. int(2)
  211. bool(false)
  212. string(1) "e"
  213. int(3)
  214. bool(false)
  215. string(1) "t"
  216. int(4)
  217. bool(false)
  218. string(1) "c"
  219. int(5)
  220. bool(false)
  221. string(1) "
  222. "
  223. int(6)
  224. bool(false)
  225. string(1) " "
  226. int(7)
  227. bool(false)
  228. -- File opened in mode : w+b --
  229. bool(true)
  230. int(0)
  231. bool(false)
  232. string(1) "f"
  233. int(1)
  234. bool(false)
  235. string(1) "g"
  236. int(2)
  237. bool(false)
  238. string(1) "e"
  239. int(3)
  240. bool(false)
  241. string(1) "t"
  242. int(4)
  243. bool(false)
  244. string(1) "c"
  245. int(5)
  246. bool(false)
  247. string(1) "
  248. "
  249. int(6)
  250. bool(false)
  251. string(1) " "
  252. int(7)
  253. bool(false)
  254. -- File opened in mode : w+t --
  255. bool(true)
  256. int(0)
  257. bool(false)
  258. string(1) "f"
  259. int(1)
  260. bool(false)
  261. string(1) "g"
  262. int(2)
  263. bool(false)
  264. string(1) "e"
  265. int(3)
  266. bool(false)
  267. string(1) "t"
  268. int(4)
  269. bool(false)
  270. string(1) "c"
  271. int(5)
  272. bool(false)
  273. string(1) "
  274. "
  275. int(6)
  276. bool(false)
  277. string(1) " "
  278. int(7)
  279. bool(false)
  280. Done