fgetss_variation1-win32.phpt 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. --TEST--
  2. Test fgetss() function : usage variations - write only 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 fgets on files which are opened in non readable modes
  17. w, wb, wt,
  18. a, ab, at,
  19. x, xb, xt
  20. */
  21. // include the common file related test functions
  22. include ("file.inc");
  23. echo "*** Testing fgetss() : usage variations ***\n";
  24. /* string with html and php tags */
  25. $string_with_tags = <<<EOT
  26. <test>Testing fgetss() functions</test>
  27. <?php echo "this string is within php tag"; ?> {;}<{> this
  28. is a heredoc string. <pg>ksklnm@@$$&$&^%&^%&^%&</pg>
  29. <html> html </html> <?php echo "php"; ?>
  30. this line is without any html and php tags
  31. this is a line with more than eighty character,want to check line splitting correctly after 80 characters
  32. this text contains some html tags <body> body </body> <br> br </br>
  33. this is the line with \n character.
  34. EOT;
  35. if(substr(PHP_OS, 0, 3) == "WIN") {
  36. $string_with_tags = str_replace("\r",'', $string_with_tags);
  37. }
  38. $filename = dirname(__FILE__)."/fgetss_variation1.tmp";
  39. /* try reading the file opened in different modes of reading */
  40. $file_modes = array("w","wb", "wt","a", "ab", "at","x","xb","xt");
  41. for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
  42. echo "\n-- Testing fgetss() with file opened using $file_modes[$mode_counter] mode --\n";
  43. /* create an empty file and write the strings with tags */
  44. $file_handle = fopen($filename, $file_modes[$mode_counter]);
  45. fwrite($file_handle,$string_with_tags);
  46. if(!$file_handle) {
  47. echo "Error: failed to open file $filename!\n";
  48. exit();
  49. }
  50. // rewind the file pointer to beginning of the file
  51. var_dump( filesize($filename) );
  52. var_dump( rewind($file_handle) );
  53. var_dump( ftell($file_handle) );
  54. var_dump( feof($file_handle) );
  55. /* read entire file and strip tags */
  56. echo "-- fgetss() with default length, file pointer at 0 , expected : no character should be read --\n";
  57. var_dump( fgetss($file_handle) ); // expected : no character should be read
  58. var_dump( ftell($file_handle) ); //ensure that file pointer position is not changed
  59. var_dump( feof($file_handle) ); // check if end of file pointer is set
  60. // close the file
  61. fclose($file_handle);
  62. // delete the file
  63. delete_file($filename);
  64. } // end of for - mode_counter
  65. echo "Done\n";
  66. ?>
  67. --EXPECT--
  68. *** Testing fgetss() : usage variations ***
  69. -- Testing fgetss() with file opened using w mode --
  70. int(445)
  71. bool(true)
  72. int(0)
  73. bool(false)
  74. -- fgetss() with default length, file pointer at 0 , expected : no character should be read --
  75. bool(false)
  76. int(0)
  77. bool(false)
  78. -- Testing fgetss() with file opened using wb mode --
  79. int(445)
  80. bool(true)
  81. int(0)
  82. bool(false)
  83. -- fgetss() with default length, file pointer at 0 , expected : no character should be read --
  84. bool(false)
  85. int(0)
  86. bool(false)
  87. -- Testing fgetss() with file opened using wt mode --
  88. int(453)
  89. bool(true)
  90. int(0)
  91. bool(false)
  92. -- fgetss() with default length, file pointer at 0 , expected : no character should be read --
  93. bool(false)
  94. int(0)
  95. bool(false)
  96. -- Testing fgetss() with file opened using a mode --
  97. int(445)
  98. bool(true)
  99. int(0)
  100. bool(false)
  101. -- fgetss() with default length, file pointer at 0 , expected : no character should be read --
  102. bool(false)
  103. int(0)
  104. bool(false)
  105. -- Testing fgetss() with file opened using ab mode --
  106. int(445)
  107. bool(true)
  108. int(0)
  109. bool(false)
  110. -- fgetss() with default length, file pointer at 0 , expected : no character should be read --
  111. bool(false)
  112. int(0)
  113. bool(false)
  114. -- Testing fgetss() with file opened using at mode --
  115. int(453)
  116. bool(true)
  117. int(0)
  118. bool(false)
  119. -- fgetss() with default length, file pointer at 0 , expected : no character should be read --
  120. bool(false)
  121. int(0)
  122. bool(false)
  123. -- Testing fgetss() with file opened using x mode --
  124. int(445)
  125. bool(true)
  126. int(0)
  127. bool(false)
  128. -- fgetss() with default length, file pointer at 0 , expected : no character should be read --
  129. bool(false)
  130. int(0)
  131. bool(false)
  132. -- Testing fgetss() with file opened using xb mode --
  133. int(445)
  134. bool(true)
  135. int(0)
  136. bool(false)
  137. -- fgetss() with default length, file pointer at 0 , expected : no character should be read --
  138. bool(false)
  139. int(0)
  140. bool(false)
  141. -- Testing fgetss() with file opened using xt mode --
  142. int(453)
  143. bool(true)
  144. int(0)
  145. bool(false)
  146. -- fgetss() with default length, file pointer at 0 , expected : no character should be read --
  147. bool(false)
  148. int(0)
  149. bool(false)
  150. Done