fscanf_variation51.phpt 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. --TEST--
  2. Test fscanf() function: usage variations - file opened in write only mode
  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 a file for read when file is opened inwrite only mode */
  10. $file_path = dirname(__FILE__);
  11. echo "*** Test fscanf(): to read from a file opened in write only mode ***\n";
  12. // create a file
  13. $filename = "$file_path/fscanf_variation51.tmp";
  14. $file_handle = fopen($filename, "w");
  15. if($file_handle == false)
  16. exit("Error:failed to open file $filename");
  17. //writing data to the file
  18. @fwrite($file_handle,"sample text\n");
  19. //closing the file
  20. fclose($file_handle);
  21. // various formats
  22. $formats = array( "%d", "%f", "%e", "%u", " %s", "%x", "%o");
  23. $counter = 1;
  24. // various write only modes
  25. $modes = array("w", "wb", "wt",
  26. "a", "ab", "at",
  27. "x", "xb", "xt"
  28. );
  29. $counter = 1;
  30. // reading the values from file using different integer formats
  31. foreach($modes as $mode) {
  32. $file_handle = fopen($filename, $mode);
  33. if($file_handle == false) {
  34. exit("Error:failed to open file $filename");
  35. }
  36. echo "\n-- iteration $counter --\n";
  37. foreach($formats as $format) {
  38. var_dump( fscanf($file_handle,$format) );
  39. rewind($file_handle);
  40. }
  41. $counter++;
  42. fclose($file_handle);
  43. unlink($filename);
  44. }
  45. echo "\n*** Done ***";
  46. ?>
  47. --CLEAN--
  48. <?php
  49. $file_path = dirname(__FILE__);
  50. $filename = "$file_path/fscanf_variation51.tmp";
  51. if(file_exists($filename)) {
  52. unlink($filename);
  53. }
  54. ?>
  55. --EXPECT--
  56. *** Test fscanf(): to read from a file opened in write only mode ***
  57. -- iteration 1 --
  58. bool(false)
  59. bool(false)
  60. bool(false)
  61. bool(false)
  62. bool(false)
  63. bool(false)
  64. bool(false)
  65. -- iteration 2 --
  66. bool(false)
  67. bool(false)
  68. bool(false)
  69. bool(false)
  70. bool(false)
  71. bool(false)
  72. bool(false)
  73. -- iteration 3 --
  74. bool(false)
  75. bool(false)
  76. bool(false)
  77. bool(false)
  78. bool(false)
  79. bool(false)
  80. bool(false)
  81. -- iteration 4 --
  82. bool(false)
  83. bool(false)
  84. bool(false)
  85. bool(false)
  86. bool(false)
  87. bool(false)
  88. bool(false)
  89. -- iteration 5 --
  90. bool(false)
  91. bool(false)
  92. bool(false)
  93. bool(false)
  94. bool(false)
  95. bool(false)
  96. bool(false)
  97. -- iteration 6 --
  98. bool(false)
  99. bool(false)
  100. bool(false)
  101. bool(false)
  102. bool(false)
  103. bool(false)
  104. bool(false)
  105. -- iteration 7 --
  106. bool(false)
  107. bool(false)
  108. bool(false)
  109. bool(false)
  110. bool(false)
  111. bool(false)
  112. bool(false)
  113. -- iteration 8 --
  114. bool(false)
  115. bool(false)
  116. bool(false)
  117. bool(false)
  118. bool(false)
  119. bool(false)
  120. bool(false)
  121. -- iteration 9 --
  122. bool(false)
  123. bool(false)
  124. bool(false)
  125. bool(false)
  126. bool(false)
  127. bool(false)
  128. bool(false)
  129. *** Done ***