fscanf_variation32.phpt 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. --TEST--
  2. Test fscanf() function: usage variations - octal formats with boolean
  3. --FILE--
  4. <?php
  5. /*
  6. Prototype: mixed fscanf ( resource $handle, string $format [, mixed &$...] );
  7. Description: Parses input from a file according to a format
  8. */
  9. /* Test fscanf() to scan boolean data using different octal format types */
  10. $file_path = dirname(__FILE__);
  11. echo "*** Test fscanf(): different octal format types with boolean data ***\n";
  12. // create a file
  13. $filename = "$file_path/fscanf_variation32.tmp";
  14. $file_handle = fopen($filename, "w");
  15. if($file_handle == false)
  16. exit("Error:failed to open file $filename");
  17. // array of boolean types
  18. $bool_types = array (
  19. true,
  20. false,
  21. TRUE,
  22. FALSE,
  23. );
  24. $octal_formats = array( "%o",
  25. "%ho", "%lo", "%Lo",
  26. " %o", "%o ", "% o",
  27. "\t%o", "\n%o", "%4o",
  28. "%30o", "%[0-7]", "%*o"
  29. );
  30. $counter = 1;
  31. // writing to the file
  32. foreach($bool_types as $value) {
  33. @fprintf($file_handle, $value);
  34. @fprintf($file_handle, "\n");
  35. }
  36. // closing the file
  37. fclose($file_handle);
  38. // opening the file for reading
  39. $file_handle = fopen($filename, "r");
  40. if($file_handle == false) {
  41. exit("Error:failed to open file $filename");
  42. }
  43. $counter = 1;
  44. // reading the values from file using different octal formats
  45. foreach($octal_formats as $octal_format) {
  46. // rewind the file so that for every foreach iteration the file pointer starts from bof
  47. rewind($file_handle);
  48. echo "\n-- iteration $counter --\n";
  49. while( !feof($file_handle) ) {
  50. var_dump( fscanf($file_handle,$octal_format) );
  51. }
  52. $counter++;
  53. }
  54. echo "\n*** Done ***";
  55. ?>
  56. --CLEAN--
  57. <?php
  58. $file_path = dirname(__FILE__);
  59. $filename = "$file_path/fscanf_variation32.tmp";
  60. unlink($filename);
  61. ?>
  62. --EXPECTF--
  63. *** Test fscanf(): different octal format types with boolean data ***
  64. -- iteration 1 --
  65. array(1) {
  66. [0]=>
  67. int(1)
  68. }
  69. NULL
  70. array(1) {
  71. [0]=>
  72. int(1)
  73. }
  74. NULL
  75. bool(false)
  76. -- iteration 2 --
  77. array(1) {
  78. [0]=>
  79. int(1)
  80. }
  81. NULL
  82. array(1) {
  83. [0]=>
  84. int(1)
  85. }
  86. NULL
  87. bool(false)
  88. -- iteration 3 --
  89. array(1) {
  90. [0]=>
  91. int(1)
  92. }
  93. NULL
  94. array(1) {
  95. [0]=>
  96. int(1)
  97. }
  98. NULL
  99. bool(false)
  100. -- iteration 4 --
  101. array(1) {
  102. [0]=>
  103. int(1)
  104. }
  105. NULL
  106. array(1) {
  107. [0]=>
  108. int(1)
  109. }
  110. NULL
  111. bool(false)
  112. -- iteration 5 --
  113. array(1) {
  114. [0]=>
  115. int(1)
  116. }
  117. NULL
  118. array(1) {
  119. [0]=>
  120. int(1)
  121. }
  122. NULL
  123. bool(false)
  124. -- iteration 6 --
  125. array(1) {
  126. [0]=>
  127. int(1)
  128. }
  129. NULL
  130. array(1) {
  131. [0]=>
  132. int(1)
  133. }
  134. NULL
  135. bool(false)
  136. -- iteration 7 --
  137. Warning: fscanf(): Bad scan conversion character " " in %s on line %d
  138. NULL
  139. Warning: fscanf(): Bad scan conversion character " " in %s on line %d
  140. NULL
  141. Warning: fscanf(): Bad scan conversion character " " in %s on line %d
  142. NULL
  143. Warning: fscanf(): Bad scan conversion character " " in %s on line %d
  144. NULL
  145. bool(false)
  146. -- iteration 8 --
  147. array(1) {
  148. [0]=>
  149. int(1)
  150. }
  151. NULL
  152. array(1) {
  153. [0]=>
  154. int(1)
  155. }
  156. NULL
  157. bool(false)
  158. -- iteration 9 --
  159. array(1) {
  160. [0]=>
  161. int(1)
  162. }
  163. NULL
  164. array(1) {
  165. [0]=>
  166. int(1)
  167. }
  168. NULL
  169. bool(false)
  170. -- iteration 10 --
  171. array(1) {
  172. [0]=>
  173. int(1)
  174. }
  175. NULL
  176. array(1) {
  177. [0]=>
  178. int(1)
  179. }
  180. NULL
  181. bool(false)
  182. -- iteration 11 --
  183. array(1) {
  184. [0]=>
  185. int(1)
  186. }
  187. NULL
  188. array(1) {
  189. [0]=>
  190. int(1)
  191. }
  192. NULL
  193. bool(false)
  194. -- iteration 12 --
  195. array(1) {
  196. [0]=>
  197. string(1) "1"
  198. }
  199. array(1) {
  200. [0]=>
  201. NULL
  202. }
  203. array(1) {
  204. [0]=>
  205. string(1) "1"
  206. }
  207. array(1) {
  208. [0]=>
  209. NULL
  210. }
  211. bool(false)
  212. -- iteration 13 --
  213. array(0) {
  214. }
  215. NULL
  216. array(0) {
  217. }
  218. NULL
  219. bool(false)
  220. *** Done ***