1--TEST-- 2Test fgetss() function : usage variations - read/write modes 3--SKIPIF-- 4<?php 5if (substr(PHP_OS, 0, 3) != 'WIN') { 6 die('skip.. only valid for Windows'); 7} 8?> 9--FILE-- 10<?php 11error_reporting(E_ALL & ~E_DEPRECATED); 12 13/* 14 Prototype: string fgetss ( resource $handle [, int $length [, string $allowable_tags]] ); 15 Description: Gets line from file pointer and strip HTML tags 16*/ 17 18/* try fgetss on files which are opened in read/write modes 19 w+, w+b, w+t, 20 a+, a+b, a+t, 21 x+, x+b, x+t 22 reading line by line with allowable tags: <test>, <html>, <?> 23*/ 24 25 26echo "*** Testing fgetss() : usage variations ***\n"; 27 28/* string with html and php tags */ 29$string_with_tags = <<<EOT 30<test>Testing fgetss() functions</test> 31<?php echo "this string is within php tag"; ?> {;}<{> this 32is a heredoc string. <pg>ksklnm@@$$&$&^%&^%&^%&</pg> 33<html> html </html> <?php echo "php"; ?> 34this line is without any html and php tags 35this is a line with more than eighty character,want to check line splitting correctly after 80 characters 36this text contains some html tags <body> body </body> <br> br </br> 37this is the line with \n character. 38EOT; 39 40if(substr(PHP_OS, 0, 3) == "WIN") { 41 $string_with_tags = str_replace("\r",'', $string_with_tags); 42} 43 44$filename = __DIR__."/fgetss_variation3.tmp"; 45 46/* try reading the file opened in different modes of reading */ 47$file_modes = array("w+","w+b", "w+t","a+", "a+b", "a+t","x+","x+b","x+t"); 48 49for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { 50 echo "\n-- Testing fgetss() with file opened using $file_modes[$mode_counter] mode --\n"; 51 52 /* create an empty file and write the strings with tags */ 53 $file_handle = fopen($filename, $file_modes[$mode_counter]); 54 fwrite($file_handle,$string_with_tags); //writing data to the file 55 if(!$file_handle) { 56 echo "Error: failed to open file $filename!\n"; 57 exit(); 58 } 59 60 // rewind the file pointer to beginning of the file 61 rewind($file_handle); 62 var_dump( ftell($file_handle) ); 63 var_dump( filesize($filename) ); 64 var_dump( feof($file_handle) ); 65 66 /* rewind the file and read the file line by line with allowable tags */ 67 echo "-- Reading line by line with allowable tags: <test>, <html>, <?> --\n"; 68 $line = 1; 69 while( !feof($file_handle) ) { 70 echo "-- Line $line --\n"; $line++; 71 var_dump( fgetss($file_handle, 80, "<test>, <html>, <?>") ); 72 var_dump( ftell($file_handle) ); // check the file pointer position 73 var_dump( feof($file_handle) ); // check if eof reached 74 } 75 76 // close the file 77 fclose($file_handle); 78 79 // delete the file 80 unlink($filename); 81} // end of for - mode_counter 82 83echo "Done\n"; 84?> 85--EXPECT-- 86*** Testing fgetss() : usage variations *** 87 88-- Testing fgetss() with file opened using w+ mode -- 89int(0) 90int(445) 91bool(false) 92-- Reading line by line with allowable tags: <test>, <html>, <?> -- 93-- Line 1 -- 94string(40) "<test>Testing fgetss() functions</test> 95" 96int(40) 97bool(false) 98-- Line 2 -- 99string(10) " {;} this 100" 101int(99) 102bool(false) 103-- Line 3 -- 104string(44) "is a heredoc string. ksklnm@@$$&$&^%&^%&^%& 105" 106int(152) 107bool(false) 108-- Line 4 -- 109string(21) "<html> html </html> 110" 111int(193) 112bool(false) 113-- Line 5 -- 114string(43) "this line is without any html and php tags 115" 116int(236) 117bool(false) 118-- Line 6 -- 119string(79) "this is a line with more than eighty character,want to check line splitting cor" 120int(315) 121bool(false) 122-- Line 7 -- 123string(27) "rectly after 80 characters 124" 125int(342) 126bool(false) 127-- Line 8 -- 128string(46) "this text contains some html tags body br 129" 130int(410) 131bool(false) 132-- Line 9 -- 133string(23) "this is the line with 134" 135int(433) 136bool(false) 137-- Line 10 -- 138string(12) " character. " 139int(445) 140bool(true) 141 142-- Testing fgetss() with file opened using w+b mode -- 143int(0) 144int(445) 145bool(false) 146-- Reading line by line with allowable tags: <test>, <html>, <?> -- 147-- Line 1 -- 148string(40) "<test>Testing fgetss() functions</test> 149" 150int(40) 151bool(false) 152-- Line 2 -- 153string(10) " {;} this 154" 155int(99) 156bool(false) 157-- Line 3 -- 158string(44) "is a heredoc string. ksklnm@@$$&$&^%&^%&^%& 159" 160int(152) 161bool(false) 162-- Line 4 -- 163string(21) "<html> html </html> 164" 165int(193) 166bool(false) 167-- Line 5 -- 168string(43) "this line is without any html and php tags 169" 170int(236) 171bool(false) 172-- Line 6 -- 173string(79) "this is a line with more than eighty character,want to check line splitting cor" 174int(315) 175bool(false) 176-- Line 7 -- 177string(27) "rectly after 80 characters 178" 179int(342) 180bool(false) 181-- Line 8 -- 182string(46) "this text contains some html tags body br 183" 184int(410) 185bool(false) 186-- Line 9 -- 187string(23) "this is the line with 188" 189int(433) 190bool(false) 191-- Line 10 -- 192string(12) " character. " 193int(445) 194bool(true) 195 196-- Testing fgetss() with file opened using w+t mode -- 197int(0) 198int(453) 199bool(false) 200-- Reading line by line with allowable tags: <test>, <html>, <?> -- 201-- Line 1 -- 202string(40) "<test>Testing fgetss() functions</test> 203" 204int(40) 205bool(false) 206-- Line 2 -- 207string(10) " {;} this 208" 209int(99) 210bool(false) 211-- Line 3 -- 212string(44) "is a heredoc string. ksklnm@@$$&$&^%&^%&^%& 213" 214int(152) 215bool(false) 216-- Line 4 -- 217string(21) "<html> html </html> 218" 219int(193) 220bool(false) 221-- Line 5 -- 222string(43) "this line is without any html and php tags 223" 224int(236) 225bool(false) 226-- Line 6 -- 227string(79) "this is a line with more than eighty character,want to check line splitting cor" 228int(315) 229bool(false) 230-- Line 7 -- 231string(27) "rectly after 80 characters 232" 233int(342) 234bool(false) 235-- Line 8 -- 236string(46) "this text contains some html tags body br 237" 238int(410) 239bool(false) 240-- Line 9 -- 241string(23) "this is the line with 242" 243int(433) 244bool(false) 245-- Line 10 -- 246string(12) " character. " 247int(445) 248bool(true) 249 250-- Testing fgetss() with file opened using a+ mode -- 251int(0) 252int(445) 253bool(false) 254-- Reading line by line with allowable tags: <test>, <html>, <?> -- 255-- Line 1 -- 256string(40) "<test>Testing fgetss() functions</test> 257" 258int(40) 259bool(false) 260-- Line 2 -- 261string(10) " {;} this 262" 263int(99) 264bool(false) 265-- Line 3 -- 266string(44) "is a heredoc string. ksklnm@@$$&$&^%&^%&^%& 267" 268int(152) 269bool(false) 270-- Line 4 -- 271string(21) "<html> html </html> 272" 273int(193) 274bool(false) 275-- Line 5 -- 276string(43) "this line is without any html and php tags 277" 278int(236) 279bool(false) 280-- Line 6 -- 281string(79) "this is a line with more than eighty character,want to check line splitting cor" 282int(315) 283bool(false) 284-- Line 7 -- 285string(27) "rectly after 80 characters 286" 287int(342) 288bool(false) 289-- Line 8 -- 290string(46) "this text contains some html tags body br 291" 292int(410) 293bool(false) 294-- Line 9 -- 295string(23) "this is the line with 296" 297int(433) 298bool(false) 299-- Line 10 -- 300string(12) " character. " 301int(445) 302bool(true) 303 304-- Testing fgetss() with file opened using a+b mode -- 305int(0) 306int(445) 307bool(false) 308-- Reading line by line with allowable tags: <test>, <html>, <?> -- 309-- Line 1 -- 310string(40) "<test>Testing fgetss() functions</test> 311" 312int(40) 313bool(false) 314-- Line 2 -- 315string(10) " {;} this 316" 317int(99) 318bool(false) 319-- Line 3 -- 320string(44) "is a heredoc string. ksklnm@@$$&$&^%&^%&^%& 321" 322int(152) 323bool(false) 324-- Line 4 -- 325string(21) "<html> html </html> 326" 327int(193) 328bool(false) 329-- Line 5 -- 330string(43) "this line is without any html and php tags 331" 332int(236) 333bool(false) 334-- Line 6 -- 335string(79) "this is a line with more than eighty character,want to check line splitting cor" 336int(315) 337bool(false) 338-- Line 7 -- 339string(27) "rectly after 80 characters 340" 341int(342) 342bool(false) 343-- Line 8 -- 344string(46) "this text contains some html tags body br 345" 346int(410) 347bool(false) 348-- Line 9 -- 349string(23) "this is the line with 350" 351int(433) 352bool(false) 353-- Line 10 -- 354string(12) " character. " 355int(445) 356bool(true) 357 358-- Testing fgetss() with file opened using a+t mode -- 359int(0) 360int(453) 361bool(false) 362-- Reading line by line with allowable tags: <test>, <html>, <?> -- 363-- Line 1 -- 364string(40) "<test>Testing fgetss() functions</test> 365" 366int(40) 367bool(false) 368-- Line 2 -- 369string(10) " {;} this 370" 371int(99) 372bool(false) 373-- Line 3 -- 374string(44) "is a heredoc string. ksklnm@@$$&$&^%&^%&^%& 375" 376int(152) 377bool(false) 378-- Line 4 -- 379string(21) "<html> html </html> 380" 381int(193) 382bool(false) 383-- Line 5 -- 384string(43) "this line is without any html and php tags 385" 386int(236) 387bool(false) 388-- Line 6 -- 389string(79) "this is a line with more than eighty character,want to check line splitting cor" 390int(315) 391bool(false) 392-- Line 7 -- 393string(27) "rectly after 80 characters 394" 395int(342) 396bool(false) 397-- Line 8 -- 398string(46) "this text contains some html tags body br 399" 400int(410) 401bool(false) 402-- Line 9 -- 403string(23) "this is the line with 404" 405int(433) 406bool(false) 407-- Line 10 -- 408string(12) " character. " 409int(445) 410bool(true) 411 412-- Testing fgetss() with file opened using x+ mode -- 413int(0) 414int(445) 415bool(false) 416-- Reading line by line with allowable tags: <test>, <html>, <?> -- 417-- Line 1 -- 418string(40) "<test>Testing fgetss() functions</test> 419" 420int(40) 421bool(false) 422-- Line 2 -- 423string(10) " {;} this 424" 425int(99) 426bool(false) 427-- Line 3 -- 428string(44) "is a heredoc string. ksklnm@@$$&$&^%&^%&^%& 429" 430int(152) 431bool(false) 432-- Line 4 -- 433string(21) "<html> html </html> 434" 435int(193) 436bool(false) 437-- Line 5 -- 438string(43) "this line is without any html and php tags 439" 440int(236) 441bool(false) 442-- Line 6 -- 443string(79) "this is a line with more than eighty character,want to check line splitting cor" 444int(315) 445bool(false) 446-- Line 7 -- 447string(27) "rectly after 80 characters 448" 449int(342) 450bool(false) 451-- Line 8 -- 452string(46) "this text contains some html tags body br 453" 454int(410) 455bool(false) 456-- Line 9 -- 457string(23) "this is the line with 458" 459int(433) 460bool(false) 461-- Line 10 -- 462string(12) " character. " 463int(445) 464bool(true) 465 466-- Testing fgetss() with file opened using x+b mode -- 467int(0) 468int(445) 469bool(false) 470-- Reading line by line with allowable tags: <test>, <html>, <?> -- 471-- Line 1 -- 472string(40) "<test>Testing fgetss() functions</test> 473" 474int(40) 475bool(false) 476-- Line 2 -- 477string(10) " {;} this 478" 479int(99) 480bool(false) 481-- Line 3 -- 482string(44) "is a heredoc string. ksklnm@@$$&$&^%&^%&^%& 483" 484int(152) 485bool(false) 486-- Line 4 -- 487string(21) "<html> html </html> 488" 489int(193) 490bool(false) 491-- Line 5 -- 492string(43) "this line is without any html and php tags 493" 494int(236) 495bool(false) 496-- Line 6 -- 497string(79) "this is a line with more than eighty character,want to check line splitting cor" 498int(315) 499bool(false) 500-- Line 7 -- 501string(27) "rectly after 80 characters 502" 503int(342) 504bool(false) 505-- Line 8 -- 506string(46) "this text contains some html tags body br 507" 508int(410) 509bool(false) 510-- Line 9 -- 511string(23) "this is the line with 512" 513int(433) 514bool(false) 515-- Line 10 -- 516string(12) " character. " 517int(445) 518bool(true) 519 520-- Testing fgetss() with file opened using x+t mode -- 521int(0) 522int(453) 523bool(false) 524-- Reading line by line with allowable tags: <test>, <html>, <?> -- 525-- Line 1 -- 526string(40) "<test>Testing fgetss() functions</test> 527" 528int(40) 529bool(false) 530-- Line 2 -- 531string(10) " {;} this 532" 533int(99) 534bool(false) 535-- Line 3 -- 536string(44) "is a heredoc string. ksklnm@@$$&$&^%&^%&^%& 537" 538int(152) 539bool(false) 540-- Line 4 -- 541string(21) "<html> html </html> 542" 543int(193) 544bool(false) 545-- Line 5 -- 546string(43) "this line is without any html and php tags 547" 548int(236) 549bool(false) 550-- Line 6 -- 551string(79) "this is a line with more than eighty character,want to check line splitting cor" 552int(315) 553bool(false) 554-- Line 7 -- 555string(27) "rectly after 80 characters 556" 557int(342) 558bool(false) 559-- Line 8 -- 560string(46) "this text contains some html tags body br 561" 562int(410) 563bool(false) 564-- Line 9 -- 565string(23) "this is the line with 566" 567int(433) 568bool(false) 569-- Line 10 -- 570string(12) " character. " 571int(445) 572bool(true) 573Done 574