fgetss_basic2.phpt 5.2 KB

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