fgetss_variation5-win32.phpt 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. --TEST--
  2. Test fgetss() function : usage variations - read/write modes, file pointer at EOF
  3. --SKIPIF--
  4. <?php
  5. if (substr(PHP_OS, 0, 3) != 'WIN') {
  6. die('skip.. only 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() : usage variations ***\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. this line is without any html and php tags
  29. this is a line with more than eighty character,want to check line splitting correctly after 80 characters
  30. this text contains some html tags <body> body </body> <br> br </br>
  31. this is the line with \n character.
  32. EOT;
  33. if(substr(PHP_OS, 0, 3) == "WIN") {
  34. $string_with_tags = str_replace("\r",'', $string_with_tags);
  35. }
  36. $filename = dirname(__FILE__)."/fgetss_variation5.tmp";
  37. /* try reading the file opened in different modes of reading */
  38. $file_modes = array("w+","w+b", "w+t","a+", "a+b", "a+t","x+","x+b","x+t");
  39. for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
  40. echo "\n-- Testing fgetss() with file opened using $file_modes[$mode_counter] mode --\n";
  41. /* create an empty file and write the strings with tags */
  42. $file_handle = fopen($filename, $file_modes[$mode_counter]);
  43. fwrite($file_handle,$string_with_tags); //writing data to the file
  44. if(!$file_handle) {
  45. echo "Error: failed to open file $filename!\n";
  46. exit();
  47. }
  48. // rewind the file pointer to beginning of the file
  49. var_dump( filesize($filename) );
  50. var_dump( rewind($file_handle) );
  51. var_dump( ftell($file_handle) );
  52. var_dump( feof($file_handle) );
  53. echo "-- Reading when file pointer points to EOF --\n";
  54. var_dump( fseek($file_handle,0,SEEK_END) ); // now file pointer at end
  55. var_dump( ftell($file_handle) ); //ensure file pointer at end
  56. var_dump( fgetss($file_handle) ); // try to read
  57. var_dump( ftell($file_handle) ); // find out file position
  58. var_dump( feof($file_handle) ); // ensure that file pointer is at eof
  59. // now file is at the end try reading with length and allowable tags,expecting false
  60. var_dump( fgetss($file_handle, 80, "<test>, <html>, <?>") );
  61. var_dump( ftell($file_handle) ); // find out file position
  62. var_dump( feof($file_handle) ); // ensure that file pointer is at eof
  63. // close the file
  64. fclose($file_handle);
  65. // delete the file
  66. unlink($filename);
  67. } // end of for - mode_counter
  68. echo "Done\n";
  69. ?>
  70. --EXPECT--
  71. *** Testing fgetss() : usage variations ***
  72. -- Testing fgetss() with file opened using w+ mode --
  73. int(445)
  74. bool(true)
  75. int(0)
  76. bool(false)
  77. -- Reading when file pointer points to EOF --
  78. int(0)
  79. int(445)
  80. bool(false)
  81. int(445)
  82. bool(true)
  83. bool(false)
  84. int(445)
  85. bool(true)
  86. -- Testing fgetss() with file opened using w+b mode --
  87. int(445)
  88. bool(true)
  89. int(0)
  90. bool(false)
  91. -- Reading when file pointer points to EOF --
  92. int(0)
  93. int(445)
  94. bool(false)
  95. int(445)
  96. bool(true)
  97. bool(false)
  98. int(445)
  99. bool(true)
  100. -- Testing fgetss() with file opened using w+t mode --
  101. int(453)
  102. bool(true)
  103. int(0)
  104. bool(false)
  105. -- Reading when file pointer points to EOF --
  106. int(0)
  107. int(453)
  108. bool(false)
  109. int(453)
  110. bool(true)
  111. bool(false)
  112. int(453)
  113. bool(true)
  114. -- Testing fgetss() with file opened using a+ mode --
  115. int(445)
  116. bool(true)
  117. int(0)
  118. bool(false)
  119. -- Reading when file pointer points to EOF --
  120. int(0)
  121. int(445)
  122. bool(false)
  123. int(445)
  124. bool(true)
  125. bool(false)
  126. int(445)
  127. bool(true)
  128. -- Testing fgetss() with file opened using a+b mode --
  129. int(445)
  130. bool(true)
  131. int(0)
  132. bool(false)
  133. -- Reading when file pointer points to EOF --
  134. int(0)
  135. int(445)
  136. bool(false)
  137. int(445)
  138. bool(true)
  139. bool(false)
  140. int(445)
  141. bool(true)
  142. -- Testing fgetss() with file opened using a+t mode --
  143. int(453)
  144. bool(true)
  145. int(0)
  146. bool(false)
  147. -- Reading when file pointer points to EOF --
  148. int(0)
  149. int(453)
  150. bool(false)
  151. int(453)
  152. bool(true)
  153. bool(false)
  154. int(453)
  155. bool(true)
  156. -- Testing fgetss() with file opened using x+ mode --
  157. int(445)
  158. bool(true)
  159. int(0)
  160. bool(false)
  161. -- Reading when file pointer points to EOF --
  162. int(0)
  163. int(445)
  164. bool(false)
  165. int(445)
  166. bool(true)
  167. bool(false)
  168. int(445)
  169. bool(true)
  170. -- Testing fgetss() with file opened using x+b mode --
  171. int(445)
  172. bool(true)
  173. int(0)
  174. bool(false)
  175. -- Reading when file pointer points to EOF --
  176. int(0)
  177. int(445)
  178. bool(false)
  179. int(445)
  180. bool(true)
  181. bool(false)
  182. int(445)
  183. bool(true)
  184. -- Testing fgetss() with file opened using x+t mode --
  185. int(453)
  186. bool(true)
  187. int(0)
  188. bool(false)
  189. -- Reading when file pointer points to EOF --
  190. int(0)
  191. int(453)
  192. bool(false)
  193. int(453)
  194. bool(true)
  195. bool(false)
  196. int(453)
  197. bool(true)
  198. Done