fgetss_variation1.phpt 4.4 KB

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