fgetss_variation1-win32.phpt 4.5 KB

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