fgetss_basic1.phpt 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. --TEST--
  2. Test fgetss() function : Basic functionality - read modes only
  3. --FILE--
  4. <?php
  5. /*
  6. Prototype: string fgetss ( resource $handle [, int $length [, string $allowable_tags]] );
  7. Description: Gets line from file pointer and strip HTML tags
  8. */
  9. /* test fgetss with all read modes */
  10. // include the common file related test functions
  11. include ("file.inc");
  12. echo "*** Testing fgetss() : Basic operations ***\n";
  13. /* string with html and php tags */
  14. $string_with_tags = <<<EOT
  15. <test>Testing fgetss() functions</test>
  16. <?php echo "this string is within php tag"; ?> {;}<{> this
  17. is a heredoc string. <pg>ksklnm@@$$&$&^%&^%&^%&</pg>
  18. <html> html </html> <?php echo "php"; ?>
  19. EOT;
  20. if(substr(PHP_OS, 0, 3) == "WIN") {
  21. $string_with_tags = str_replace("\r",'', $string_with_tags);
  22. }
  23. /* try reading the file opened in different modes of reading */
  24. $file_modes = array("r","rb", "rt","r+", "r+b", "r+t");
  25. for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
  26. echo "\n-- Testing fgetss() with file opened using $file_modes[$mode_counter] mode --\n";
  27. /* create an empty file and write the strings with tags */
  28. $filename = dirname(__FILE__)."/fgetss_basic1.tmp";
  29. create_file ($filename); //create an empty file
  30. file_put_contents($filename, $string_with_tags);
  31. $file_handle = fopen($filename, $file_modes[$mode_counter]);
  32. if(!$file_handle) {
  33. echo "Error: failed to open file $filename!\n";
  34. exit();
  35. }
  36. rewind($file_handle);
  37. /* read entire file and strip tags */
  38. echo "-- fgetss() with default length, file pointer at 0 --\n";
  39. var_dump( fgetss($file_handle) ); // no length and allowable tags provided, reads entire file
  40. var_dump( ftell($file_handle) );
  41. var_dump( feof($file_handle) );
  42. rewind($file_handle);
  43. /* read entire file and strip tags tags */
  44. echo "-- fgets() with length = 30, file pointer at 0 --\n";
  45. var_dump( fgetss($file_handle ,30) ); // length parameter given,not reading entire file
  46. var_dump( ftell($file_handle) ); // checking file pointer position initially
  47. var_dump( feof($file_handle) ); // confirm file pointer is not at eof
  48. // close the file
  49. fclose($file_handle);
  50. // delete the file
  51. delete_file($filename);
  52. } // end of for - mode_counter
  53. echo "Done\n";
  54. ?>
  55. --EXPECT--
  56. *** Testing fgetss() : Basic operations ***
  57. -- Testing fgetss() with file opened using r mode --
  58. -- fgetss() with default length, file pointer at 0 --
  59. string(27) "Testing fgetss() functions
  60. "
  61. int(40)
  62. bool(false)
  63. -- fgets() with length = 30, file pointer at 0 --
  64. string(23) "Testing fgetss() functi"
  65. int(29)
  66. bool(false)
  67. -- Testing fgetss() with file opened using rb mode --
  68. -- fgetss() with default length, file pointer at 0 --
  69. string(27) "Testing fgetss() functions
  70. "
  71. int(40)
  72. bool(false)
  73. -- fgets() with length = 30, file pointer at 0 --
  74. string(23) "Testing fgetss() functi"
  75. int(29)
  76. bool(false)
  77. -- Testing fgetss() with file opened using rt mode --
  78. -- fgetss() with default length, file pointer at 0 --
  79. string(27) "Testing fgetss() functions
  80. "
  81. int(40)
  82. bool(false)
  83. -- fgets() with length = 30, file pointer at 0 --
  84. string(23) "Testing fgetss() functi"
  85. int(29)
  86. bool(false)
  87. -- Testing fgetss() with file opened using r+ mode --
  88. -- fgetss() with default length, file pointer at 0 --
  89. string(27) "Testing fgetss() functions
  90. "
  91. int(40)
  92. bool(false)
  93. -- fgets() with length = 30, file pointer at 0 --
  94. string(23) "Testing fgetss() functi"
  95. int(29)
  96. bool(false)
  97. -- Testing fgetss() with file opened using r+b mode --
  98. -- fgetss() with default length, file pointer at 0 --
  99. string(27) "Testing fgetss() functions
  100. "
  101. int(40)
  102. bool(false)
  103. -- fgets() with length = 30, file pointer at 0 --
  104. string(23) "Testing fgetss() functi"
  105. int(29)
  106. bool(false)
  107. -- Testing fgetss() with file opened using r+t mode --
  108. -- fgetss() with default length, file pointer at 0 --
  109. string(27) "Testing fgetss() functions
  110. "
  111. int(40)
  112. bool(false)
  113. -- fgets() with length = 30, file pointer at 0 --
  114. string(23) "Testing fgetss() functi"
  115. int(29)
  116. bool(false)
  117. Done