fscanf_variation47.phpt 3.1 KB

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