Annotation of embedaddon/php/ext/standard/tests/strings/chop_variation4.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test chop() function : usage variations - strings with embedded nulls
                      3: --FILE--
                      4: <?php
                      5: /* Prototype  : string chop ( string $str [, string $charlist] )
                      6:  * Description: Strip whitespace (or other characters) from the end of a string
                      7:  * Source code: ext/standard/string.c
                      8: */
                      9: 
                     10: /*
                     11:  * Testing chop() : with nulls embedded in input string
                     12: */
                     13: 
                     14: echo "*** Testing chop() : string with embedded nulls ***\n";
                     15: 
                     16: // defining varous strings with embedded nulls
                     17: $strings_with_nulls = array(
                     18:                           "hello\0world",
                     19:                           "\0hello",
                     20:                           "hello\0",
                     21:                           "\0\0hello\tworld\0\0",
                     22:                           "\\0hello\\0",
                     23:                           'hello\0\0',
                     24:                           chr(0),
                     25:                           chr(0).chr(0),
                     26:                           chr(0).'hello'.chr(0),
                     27:                           'hello'.chr(0).'world'
                     28:                           );
                     29: 
                     30: $count = 1;
                     31: foreach($strings_with_nulls as $string)  {
                     32:   echo "\n--- Iteration $count ---\n";
                     33:   var_dump( chop($string) );
                     34:   var_dump( chop($string, "\0") );
                     35:   var_dump( chop($string, '\0') );
                     36:   $count++;
                     37: }
                     38: 
                     39: echo "Done\n";
                     40: ?>
                     41: --EXPECTF--
                     42: *** Testing chop() : string with embedded nulls ***
                     43: 
                     44: --- Iteration 1 ---
                     45: string(11) "helloworld"
                     46: string(11) "helloworld"
                     47: string(11) "helloworld"
                     48: 
                     49: --- Iteration 2 ---
                     50: string(6) "hello"
                     51: string(6) "hello"
                     52: string(6) "hello"
                     53: 
                     54: --- Iteration 3 ---
                     55: string(5) "hello"
                     56: string(5) "hello"
                     57: string(6) "hello"
                     58: 
                     59: --- Iteration 4 ---
                     60: string(13) "hello    world"
                     61: string(13) "hello    world"
                     62: string(15) "hello    world"
                     63: 
                     64: --- Iteration 5 ---
                     65: string(9) "\0hello\0"
                     66: string(9) "\0hello\0"
                     67: string(7) "\0hello"
                     68: 
                     69: --- Iteration 6 ---
                     70: string(9) "hello\0\0"
                     71: string(9) "hello\0\0"
                     72: string(5) "hello"
                     73: 
                     74: --- Iteration 7 ---
                     75: string(0) ""
                     76: string(0) ""
                     77: string(1) ""
                     78: 
                     79: --- Iteration 8 ---
                     80: string(0) ""
                     81: string(0) ""
                     82: string(2) ""
                     83: 
                     84: --- Iteration 9 ---
                     85: string(6) "hello"
                     86: string(6) "hello"
                     87: string(7) "hello"
                     88: 
                     89: --- Iteration 10 ---
                     90: string(11) "helloworld"
                     91: string(11) "helloworld"
                     92: string(11) "helloworld"
                     93: Done

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