fgetss_variation1.phpt 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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.. 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 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. $filename = dirname(__FILE__)."/fgetss_variation1.tmp";
  36. /* try reading the file opened in different modes of reading */
  37. $file_modes = array("w","wb", "wt","a", "ab", "at","x","xb","xt");
  38. for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
  39. echo "\n-- Testing fgetss() with file opened using $file_modes[$mode_counter] mode --\n";
  40. /* create an empty file and write the strings with tags */
  41. $file_handle = fopen($filename, $file_modes[$mode_counter]);
  42. fwrite($file_handle,$string_with_tags);
  43. if(!$file_handle) {
  44. echo "Error: failed to open file $filename!\n";
  45. exit();
  46. }
  47. // rewind the file pointer to beginning of the file
  48. var_dump( filesize($filename) );
  49. var_dump( rewind($file_handle) );
  50. var_dump( ftell($file_handle) );
  51. var_dump( feof($file_handle) );
  52. /* read entire file and strip tags */
  53. echo "-- fgetss() with default length, file pointer at 0 , expected : no character should be read --\n";
  54. var_dump( fgetss($file_handle) ); // expected : no character should be read
  55. var_dump( ftell($file_handle) ); //ensure that file pointer position is not changed
  56. var_dump( feof($file_handle) ); // check if end of file pointer is set
  57. // close the file
  58. fclose($file_handle);
  59. // delete the file
  60. delete_file($filename);
  61. } // end of for - mode_counter
  62. echo "Done\n";
  63. ?>
  64. --EXPECT--
  65. *** Testing fgetss() : usage variations ***
  66. -- Testing fgetss() with file opened using w mode --
  67. int(445)
  68. bool(true)
  69. int(0)
  70. bool(false)
  71. -- fgetss() with default length, file pointer at 0 , expected : no character should be read --
  72. bool(false)
  73. int(0)
  74. bool(false)
  75. -- Testing fgetss() with file opened using wb mode --
  76. int(445)
  77. bool(true)
  78. int(0)
  79. bool(false)
  80. -- fgetss() with default length, file pointer at 0 , expected : no character should be read --
  81. bool(false)
  82. int(0)
  83. bool(false)
  84. -- Testing fgetss() with file opened using wt mode --
  85. int(445)
  86. bool(true)
  87. int(0)
  88. bool(false)
  89. -- fgetss() with default length, file pointer at 0 , expected : no character should be read --
  90. bool(false)
  91. int(0)
  92. bool(false)
  93. -- Testing fgetss() with file opened using a mode --
  94. int(445)
  95. bool(true)
  96. int(0)
  97. bool(false)
  98. -- fgetss() with default length, file pointer at 0 , expected : no character should be read --
  99. bool(false)
  100. int(0)
  101. bool(false)
  102. -- Testing fgetss() with file opened using ab mode --
  103. int(445)
  104. bool(true)
  105. int(0)
  106. bool(false)
  107. -- fgetss() with default length, file pointer at 0 , expected : no character should be read --
  108. bool(false)
  109. int(0)
  110. bool(false)
  111. -- Testing fgetss() with file opened using at mode --
  112. int(445)
  113. bool(true)
  114. int(0)
  115. bool(false)
  116. -- fgetss() with default length, file pointer at 0 , expected : no character should be read --
  117. bool(false)
  118. int(0)
  119. bool(false)
  120. -- Testing fgetss() with file opened using x mode --
  121. int(445)
  122. bool(true)
  123. int(0)
  124. bool(false)
  125. -- fgetss() with default length, file pointer at 0 , expected : no character should be read --
  126. bool(false)
  127. int(0)
  128. bool(false)
  129. -- Testing fgetss() with file opened using xb mode --
  130. int(445)
  131. bool(true)
  132. int(0)
  133. bool(false)
  134. -- fgetss() with default length, file pointer at 0 , expected : no character should be read --
  135. bool(false)
  136. int(0)
  137. bool(false)
  138. -- Testing fgetss() with file opened using xt mode --
  139. int(445)
  140. bool(true)
  141. int(0)
  142. bool(false)
  143. -- fgetss() with default length, file pointer at 0 , expected : no character should be read --
  144. bool(false)
  145. int(0)
  146. bool(false)
  147. Done