123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434 |
- --TEST--
- Test fgetss() function : usage variations - read modes
- --FILE--
- <?php
- /*
- Prototype: string fgetss ( resource $handle [, int $length [, string $allowable_tags]] );
- Description: Gets line from file pointer and strip HTML tags
- */
- // include the common file related test functions
- include ("file.inc");
- /*Test fgetss() with all read modes , reading line by line with allowable tags: <test>, <html>, <?> */
- echo "*** Testing fgetss() : usage variations ***\n";
- /* string with html and php tags */
- $string_with_tags = <<<EOT
- <test>Testing fgetss() functions</test>
- <?php echo "this string is within php tag"; ?> {;}<{> this
- is a heredoc string. <pg>ksklnm@@$$&$&^%&^%&^%&</pg>
- <html> html </html> <?php echo "php"; ?>
- this line is without any html and php tags
- this is a line with more than eighty character,want to check line splitting correctly after 80 characters
- this is the text containing \r character
- this text contains some html tags <body> body </body> <br> br </br>
- this is the line with \n character.
- EOT;
- $filename = dirname(__FILE__)."/fgetss_variation2.tmp";
- /* try reading the file opened in different modes of reading */
- $file_modes = array("r","rb", "rt","r+", "r+b", "r+t");
- for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
- echo "\n-- Testing fgetss() with file opened using $file_modes[$mode_counter] mode --\n";
- /* create an empty file and write the strings with tags */
- create_file ($filename); //create an empty file
- file_put_contents($filename, $string_with_tags);
- $file_handle = fopen($filename, $file_modes[$mode_counter]);
- if(!$file_handle) {
- echo "Error: failed to open file $filename!\n";
- exit();
- }
- // rewind the file pointer to beginning of the file
- var_dump( filesize($filename) );
- var_dump( rewind($file_handle) );
- var_dump( ftell($file_handle) );
- var_dump( feof($file_handle) );
-
- /* rewind the file and read the file line by line with allowable tags */
- echo "-- Reading line by line with allowable tags: <test>, <html>, <?> --\n";
- rewind($file_handle);
- $line = 1;
- while( !feof($file_handle) ) {
- echo "-- Line $line --\n"; $line++;
- var_dump( fgetss($file_handle, 80, "<test>, <html>, <?>") );
- var_dump( ftell($file_handle) ); // check the file pointer position
- var_dump( feof($file_handle) ); // check if eof reached
- }
-
- // close the file
- fclose($file_handle);
- // delete the file
- delete_file($filename);
- } // end of for - mode_counter
- echo "Done\n";
- ?>
- --EXPECTF--
- *** Testing fgetss() : usage variations ***
- -- Testing fgetss() with file opened using r mode --
- int(486)
- bool(true)
- int(0)
- bool(false)
- -- Reading line by line with allowable tags: <test>, <html>, <?> --
- -- Line 1 --
- string(40) "<test>Testing fgetss() functions</test>
- "
- int(40)
- bool(false)
- -- Line 2 --
- string(10) " {;} this
- "
- int(99)
- bool(false)
- -- Line 3 --
- string(44) "is a heredoc string. ksklnm@@$$&$&^%&^%&^%&
- "
- int(152)
- bool(false)
- -- Line 4 --
- string(21) "<html> html </html>
- "
- int(193)
- bool(false)
- -- Line 5 --
- string(43) "this line is without any html and php tags
- "
- int(236)
- bool(false)
- -- Line 6 --
- string(79) "this is a line with more than eighty character,want to check line splitting cor"
- int(315)
- bool(false)
- -- Line 7 --
- string(27) "rectly after 80 characters
- "
- int(342)
- bool(false)
- -- Line 8 --
- string(41) "this is the text containing
character
- "
- int(383)
- bool(false)
- -- Line 9 --
- string(46) "this text contains some html tags body br
- "
- int(451)
- bool(false)
- -- Line 10 --
- string(23) "this is the line with
- "
- int(474)
- bool(false)
- -- Line 11 --
- string(12) " character. "
- int(486)
- bool(true)
- -- Testing fgetss() with file opened using rb mode --
- int(486)
- bool(true)
- int(0)
- bool(false)
- -- Reading line by line with allowable tags: <test>, <html>, <?> --
- -- Line 1 --
- string(40) "<test>Testing fgetss() functions</test>
- "
- int(40)
- bool(false)
- -- Line 2 --
- string(10) " {;} this
- "
- int(99)
- bool(false)
- -- Line 3 --
- string(44) "is a heredoc string. ksklnm@@$$&$&^%&^%&^%&
- "
- int(152)
- bool(false)
- -- Line 4 --
- string(21) "<html> html </html>
- "
- int(193)
- bool(false)
- -- Line 5 --
- string(43) "this line is without any html and php tags
- "
- int(236)
- bool(false)
- -- Line 6 --
- string(79) "this is a line with more than eighty character,want to check line splitting cor"
- int(315)
- bool(false)
- -- Line 7 --
- string(27) "rectly after 80 characters
- "
- int(342)
- bool(false)
- -- Line 8 --
- string(41) "this is the text containing
character
- "
- int(383)
- bool(false)
- -- Line 9 --
- string(46) "this text contains some html tags body br
- "
- int(451)
- bool(false)
- -- Line 10 --
- string(23) "this is the line with
- "
- int(474)
- bool(false)
- -- Line 11 --
- string(12) " character. "
- int(486)
- bool(true)
- -- Testing fgetss() with file opened using rt mode --
- int(486)
- bool(true)
- int(0)
- bool(false)
- -- Reading line by line with allowable tags: <test>, <html>, <?> --
- -- Line 1 --
- string(40) "<test>Testing fgetss() functions</test>
- "
- int(40)
- bool(false)
- -- Line 2 --
- string(10) " {;} this
- "
- int(99)
- bool(false)
- -- Line 3 --
- string(44) "is a heredoc string. ksklnm@@$$&$&^%&^%&^%&
- "
- int(152)
- bool(false)
- -- Line 4 --
- string(21) "<html> html </html>
- "
- int(193)
- bool(false)
- -- Line 5 --
- string(43) "this line is without any html and php tags
- "
- int(236)
- bool(false)
- -- Line 6 --
- string(79) "this is a line with more than eighty character,want to check line splitting cor"
- int(315)
- bool(false)
- -- Line 7 --
- string(27) "rectly after 80 characters
- "
- int(342)
- bool(false)
- -- Line 8 --
- string(41) "this is the text containing
character
- "
- int(383)
- bool(false)
- -- Line 9 --
- string(46) "this text contains some html tags body br
- "
- int(451)
- bool(false)
- -- Line 10 --
- string(23) "this is the line with
- "
- int(474)
- bool(false)
- -- Line 11 --
- string(12) " character. "
- int(486)
- bool(true)
- -- Testing fgetss() with file opened using r+ mode --
- int(486)
- bool(true)
- int(0)
- bool(false)
- -- Reading line by line with allowable tags: <test>, <html>, <?> --
- -- Line 1 --
- string(40) "<test>Testing fgetss() functions</test>
- "
- int(40)
- bool(false)
- -- Line 2 --
- string(10) " {;} this
- "
- int(99)
- bool(false)
- -- Line 3 --
- string(44) "is a heredoc string. ksklnm@@$$&$&^%&^%&^%&
- "
- int(152)
- bool(false)
- -- Line 4 --
- string(21) "<html> html </html>
- "
- int(193)
- bool(false)
- -- Line 5 --
- string(43) "this line is without any html and php tags
- "
- int(236)
- bool(false)
- -- Line 6 --
- string(79) "this is a line with more than eighty character,want to check line splitting cor"
- int(315)
- bool(false)
- -- Line 7 --
- string(27) "rectly after 80 characters
- "
- int(342)
- bool(false)
- -- Line 8 --
- string(41) "this is the text containing
character
- "
- int(383)
- bool(false)
- -- Line 9 --
- string(46) "this text contains some html tags body br
- "
- int(451)
- bool(false)
- -- Line 10 --
- string(23) "this is the line with
- "
- int(474)
- bool(false)
- -- Line 11 --
- string(12) " character. "
- int(486)
- bool(true)
- -- Testing fgetss() with file opened using r+b mode --
- int(486)
- bool(true)
- int(0)
- bool(false)
- -- Reading line by line with allowable tags: <test>, <html>, <?> --
- -- Line 1 --
- string(40) "<test>Testing fgetss() functions</test>
- "
- int(40)
- bool(false)
- -- Line 2 --
- string(10) " {;} this
- "
- int(99)
- bool(false)
- -- Line 3 --
- string(44) "is a heredoc string. ksklnm@@$$&$&^%&^%&^%&
- "
- int(152)
- bool(false)
- -- Line 4 --
- string(21) "<html> html </html>
- "
- int(193)
- bool(false)
- -- Line 5 --
- string(43) "this line is without any html and php tags
- "
- int(236)
- bool(false)
- -- Line 6 --
- string(79) "this is a line with more than eighty character,want to check line splitting cor"
- int(315)
- bool(false)
- -- Line 7 --
- string(27) "rectly after 80 characters
- "
- int(342)
- bool(false)
- -- Line 8 --
- string(41) "this is the text containing
character
- "
- int(383)
- bool(false)
- -- Line 9 --
- string(46) "this text contains some html tags body br
- "
- int(451)
- bool(false)
- -- Line 10 --
- string(23) "this is the line with
- "
- int(474)
- bool(false)
- -- Line 11 --
- string(12) " character. "
- int(486)
- bool(true)
- -- Testing fgetss() with file opened using r+t mode --
- int(486)
- bool(true)
- int(0)
- bool(false)
- -- Reading line by line with allowable tags: <test>, <html>, <?> --
- -- Line 1 --
- string(40) "<test>Testing fgetss() functions</test>
- "
- int(40)
- bool(false)
- -- Line 2 --
- string(10) " {;} this
- "
- int(99)
- bool(false)
- -- Line 3 --
- string(44) "is a heredoc string. ksklnm@@$$&$&^%&^%&^%&
- "
- int(152)
- bool(false)
- -- Line 4 --
- string(21) "<html> html </html>
- "
- int(193)
- bool(false)
- -- Line 5 --
- string(43) "this line is without any html and php tags
- "
- int(236)
- bool(false)
- -- Line 6 --
- string(79) "this is a line with more than eighty character,want to check line splitting cor"
- int(315)
- bool(false)
- -- Line 7 --
- string(27) "rectly after 80 characters
- "
- int(342)
- bool(false)
- -- Line 8 --
- string(41) "this is the text containing
character
- "
- int(383)
- bool(false)
- -- Line 9 --
- string(46) "this text contains some html tags body br
- "
- int(451)
- bool(false)
- -- Line 10 --
- string(23) "this is the line with
- "
- int(474)
- bool(false)
- -- Line 11 --
- string(12) " character. "
- int(486)
- bool(true)
- Done
|