fgetss_basic2-win32-mb.phpt 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. --TEST--
  2. Test fgetss() function : Basic functionality - read/write modes
  3. --SKIPIF--
  4. <?php
  5. if (substr(PHP_OS, 0, 3) != 'WIN') {
  6. die('skip.. only on Windows');
  7. }
  8. ?>
  9. --FILE--
  10. <?php
  11. error_reporting(E_ALL & ~E_DEPRECATED);
  12. /*
  13. Prototype: string fgetss ( resource $handle [, int $length [, string $allowable_tags]] );
  14. Description: Gets line from file pointer and strip HTML tags
  15. */
  16. /* try fgetss on files which are opened in read/write modes
  17. w+, w+b, w+t,
  18. a+, a+b, a+t,
  19. x+, x+b, x+t
  20. */
  21. echo "*** Testing fgetss() : basic operations ***\n";
  22. /* string with html and php tags */
  23. $string_with_tags = <<<EOT
  24. <test>Testing fgetss() functions</test>
  25. <?php echo "this string is within php tag"; ?> {;}<{> this
  26. is a heredoc string. <pg>ksklnm@@$$&$&^%&^%&^%&</pg>
  27. <html> html </html> <?php echo "php"; ?>
  28. EOT;
  29. if(substr(PHP_OS, 0, 3) == "WIN") {
  30. $string_with_tags = str_replace("\r",'', $string_with_tags);
  31. }
  32. $filename = dirname(__FILE__)."/fgetss_basic2私はガラスを食べられます.tmp";
  33. /* try reading the file opened in different modes of reading */
  34. $file_modes = array("w+","w+b", "w+t","a+", "a+b", "a+t","x+","x+b","x+t");
  35. for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
  36. echo "\n-- Testing fgetss() with file opened using $file_modes[$mode_counter] mode --\n";
  37. /* create an empty file and write the strings with tags */
  38. $file_handle = fopen($filename, $file_modes[$mode_counter]);
  39. fwrite($file_handle,$string_with_tags); //writing data to the file
  40. if(!$file_handle) {
  41. echo "Error: failed to open file $filename!\n";
  42. exit();
  43. }
  44. // rewind the file pointer to beginning of the file
  45. var_dump( filesize($filename) );
  46. var_dump( rewind($file_handle) );
  47. var_dump( ftell($file_handle) );
  48. var_dump( feof($file_handle) );
  49. /* read entire file and strip tags */
  50. echo "-- fgetss() with default length, file pointer at 0 --\n";
  51. var_dump( fgetss($file_handle) ); // no length and allowable tags provided, reads entire file
  52. var_dump( ftell($file_handle) );
  53. var_dump( feof($file_handle) );
  54. rewind($file_handle);
  55. /* read entire file and strip tags tags */
  56. echo "-- fgets() with length = 30, file pointer at 0 --\n";
  57. var_dump( fgetss($file_handle ,30) ); // length parameter given,not reading entire file
  58. var_dump( ftell($file_handle) ); // checking file pointer position initially
  59. var_dump( feof($file_handle) ); // confirm file pointer is not at eof
  60. // close the file
  61. fclose($file_handle);
  62. // delete the file
  63. unlink($filename);
  64. } // end of for - mode_counter
  65. echo "Done\n";
  66. ?>
  67. --EXPECT--
  68. *** Testing fgetss() : basic operations ***
  69. -- Testing fgetss() with file opened using w+ mode --
  70. int(192)
  71. bool(true)
  72. int(0)
  73. bool(false)
  74. -- fgetss() with default length, file pointer at 0 --
  75. string(27) "Testing fgetss() functions
  76. "
  77. int(40)
  78. bool(false)
  79. -- fgets() with length = 30, file pointer at 0 --
  80. string(23) "Testing fgetss() functi"
  81. int(29)
  82. bool(false)
  83. -- Testing fgetss() with file opened using w+b mode --
  84. int(192)
  85. bool(true)
  86. int(0)
  87. bool(false)
  88. -- fgetss() with default length, file pointer at 0 --
  89. string(27) "Testing fgetss() functions
  90. "
  91. int(40)
  92. bool(false)
  93. -- fgets() with length = 30, file pointer at 0 --
  94. string(23) "Testing fgetss() functi"
  95. int(29)
  96. bool(false)
  97. -- Testing fgetss() with file opened using w+t mode --
  98. int(195)
  99. bool(true)
  100. int(0)
  101. bool(false)
  102. -- fgetss() with default length, file pointer at 0 --
  103. string(27) "Testing fgetss() functions
  104. "
  105. int(40)
  106. bool(false)
  107. -- fgets() with length = 30, file pointer at 0 --
  108. string(23) "Testing fgetss() functi"
  109. int(29)
  110. bool(false)
  111. -- Testing fgetss() with file opened using a+ mode --
  112. int(192)
  113. bool(true)
  114. int(0)
  115. bool(false)
  116. -- fgetss() with default length, file pointer at 0 --
  117. string(27) "Testing fgetss() functions
  118. "
  119. int(40)
  120. bool(false)
  121. -- fgets() with length = 30, file pointer at 0 --
  122. string(23) "Testing fgetss() functi"
  123. int(29)
  124. bool(false)
  125. -- Testing fgetss() with file opened using a+b mode --
  126. int(192)
  127. bool(true)
  128. int(0)
  129. bool(false)
  130. -- fgetss() with default length, file pointer at 0 --
  131. string(27) "Testing fgetss() functions
  132. "
  133. int(40)
  134. bool(false)
  135. -- fgets() with length = 30, file pointer at 0 --
  136. string(23) "Testing fgetss() functi"
  137. int(29)
  138. bool(false)
  139. -- Testing fgetss() with file opened using a+t mode --
  140. int(195)
  141. bool(true)
  142. int(0)
  143. bool(false)
  144. -- fgetss() with default length, file pointer at 0 --
  145. string(27) "Testing fgetss() functions
  146. "
  147. int(40)
  148. bool(false)
  149. -- fgets() with length = 30, file pointer at 0 --
  150. string(23) "Testing fgetss() functi"
  151. int(29)
  152. bool(false)
  153. -- Testing fgetss() with file opened using x+ mode --
  154. int(192)
  155. bool(true)
  156. int(0)
  157. bool(false)
  158. -- fgetss() with default length, file pointer at 0 --
  159. string(27) "Testing fgetss() functions
  160. "
  161. int(40)
  162. bool(false)
  163. -- fgets() with length = 30, file pointer at 0 --
  164. string(23) "Testing fgetss() functi"
  165. int(29)
  166. bool(false)
  167. -- Testing fgetss() with file opened using x+b mode --
  168. int(192)
  169. bool(true)
  170. int(0)
  171. bool(false)
  172. -- fgetss() with default length, file pointer at 0 --
  173. string(27) "Testing fgetss() functions
  174. "
  175. int(40)
  176. bool(false)
  177. -- fgets() with length = 30, file pointer at 0 --
  178. string(23) "Testing fgetss() functi"
  179. int(29)
  180. bool(false)
  181. -- Testing fgetss() with file opened using x+t mode --
  182. int(195)
  183. bool(true)
  184. int(0)
  185. bool(false)
  186. -- fgetss() with default length, file pointer at 0 --
  187. string(27) "Testing fgetss() functions
  188. "
  189. int(40)
  190. bool(false)
  191. -- fgets() with length = 30, file pointer at 0 --
  192. string(23) "Testing fgetss() functi"
  193. int(29)
  194. bool(false)
  195. Done