import zend standard tests
[hiphop-php.git] / hphp / test / zend / bad / ext-standard-file / fgetss_variation2.php
blobd757e783d7cbee2ee1d36660c6407098d7327f8d
1 <?php
2 /*
3 Prototype: string fgetss ( resource $handle [, int $length [, string $allowable_tags]] );
4 Description: Gets line from file pointer and strip HTML tags
5 */
7 // include the common file related test functions
8 include ("file.inc");
10 /*Test fgetss() with all read modes , reading line by line with allowable tags: <test>, <html>, <?> */
12 echo "*** Testing fgetss() : usage variations ***\n";
14 /* string with html and php tags */
15 $string_with_tags = <<<EOT
16 <test>Testing fgetss() functions</test>
17 <?php echo "this string is within php tag"; ?> {;}<{> this
18 is a heredoc string. <pg>ksklnm@@$$&$&^%&^%&^%&</pg>
19 <html> html </html> <?php echo "php"; ?>
20 this line is without any html and php tags
21 this is a line with more than eighty character,want to check line splitting correctly after 80 characters
22 this is the text containing \r character
23 this text contains some html tags <body> body </body> <br> br </br>
24 this is the line with \n character.
25 EOT;
27 $filename = dirname(__FILE__)."/fgetss_variation2.tmp";
29 /* try reading the file opened in different modes of reading */
30 $file_modes = array("r","rb", "rt","r+", "r+b", "r+t");
32 for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
33 echo "\n-- Testing fgetss() with file opened using $file_modes[$mode_counter] mode --\n";
35 /* create an empty file and write the strings with tags */
36 create_file ($filename); //create an empty file
37 file_put_contents($filename, $string_with_tags);
38 $file_handle = fopen($filename, $file_modes[$mode_counter]);
39 if(!$file_handle) {
40 echo "Error: failed to open file $filename!\n";
41 exit();
44 // rewind the file pointer to begining of the file
45 var_dump( filesize($filename) );
46 var_dump( rewind($file_handle) );
47 var_dump( ftell($file_handle) );
48 var_dump( feof($file_handle) );
50 /* rewind the file and read the file line by line with allowable tags */
51 echo "-- Reading line by line with allowable tags: <test>, <html>, <?> --\n";
52 rewind($file_handle);
53 $line = 1;
54 while( !feof($file_handle) ) {
55 echo "-- Line $line --\n"; $line++;
56 var_dump( fgetss($file_handle, 80, "<test>, <html>, <?>") );
57 var_dump( ftell($file_handle) ); // check the file pointer position
58 var_dump( feof($file_handle) ); // check if eof reached
61 // close the file
62 fclose($file_handle);
63 // delete the file
64 delete_file($filename);
65 } // end of for - mode_counter
67 echo "Done\n";