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