fgetss_basic2-win32.phpt 5.3 KB

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