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