Annotation of embedaddon/php/ext/standard/tests/file/fgetss_variation3.phpt, revision 1.1.1.2

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>