fscanf_variation29.phpt 3.1 KB

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