Annotation of embedaddon/php/ext/mbstring/tests/mb_substr_variation4.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test mb_substr() function : usage variations - pass different integers to $start arg
                      3: --SKIPIF--
                      4: <?php
                      5: extension_loaded('mbstring') or die('skip');
                      6: function_exists('mb_substr') or die("skip mb_substr() is not available in this build");
                      7: ?>
                      8: --FILE--
                      9: <?php
                     10: /* Prototype  : string mb_substr(string $str, int $start [, int $length [, string $encoding]])
                     11:  * Description: Returns part of a string 
                     12:  * Source code: ext/mbstring/mbstring.c
                     13:  */
                     14: 
                     15: /*
                     16:  * Test how mb_substr() behaves when passed a range of integers as $start argument
                     17:  */
                     18: 
                     19: echo "*** Testing mb_substr() : usage variations ***\n";
                     20: 
                     21: mb_internal_encoding('UTF-8');
                     22: 
                     23: $string_ascii = b'+Is an English string'; //21 chars
                     24: 
                     25: $string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII='); //21 chars
                     26: 
                     27: /*
                     28:  * Loop through integers as multiples of ten for $offset argument
                     29:  * 60 is larger than *BYTE* count for $string_mb
                     30:  */
                     31: for ($i = -60; $i <= 60; $i += 10) {
                     32:        if (@$a || @$b) {
                     33:                $a = null;
                     34:                $b = null;
                     35:        }
                     36:        echo "\n**-- Offset is: $i --**\n";
                     37:        echo "-- ASCII String --\n";
                     38:        $a = mb_substr($string_ascii, $i, 4);
                     39:        var_dump(base64_encode($a));
                     40:        echo "--Multibyte String --\n";
                     41:        $b = mb_substr($string_mb, $i, 4, 'UTF-8');
                     42:        if (strlen($a) == mb_strlen($b, 'UTF-8')) { // should return same length
                     43:                var_dump(base64_encode($b));
                     44:        } else {
                     45:                echo "Difference in length of ASCII string and multibyte string\n";
                     46:        }
                     47:        
                     48: }
                     49: 
                     50: echo "Done";
                     51: ?>
                     52: --EXPECT--
                     53: *** Testing mb_substr() : usage variations ***
                     54: 
                     55: **-- Offset is: -60 --**
                     56: -- ASCII String --
                     57: string(8) "K0lzIA=="
                     58: --Multibyte String --
                     59: string(16) "5pel5pys6Kqe44OG"
                     60: 
                     61: **-- Offset is: -50 --**
                     62: -- ASCII String --
                     63: string(8) "K0lzIA=="
                     64: --Multibyte String --
                     65: string(16) "5pel5pys6Kqe44OG"
                     66: 
                     67: **-- Offset is: -40 --**
                     68: -- ASCII String --
                     69: string(8) "K0lzIA=="
                     70: --Multibyte String --
                     71: string(16) "5pel5pys6Kqe44OG"
                     72: 
                     73: **-- Offset is: -30 --**
                     74: -- ASCII String --
                     75: string(8) "K0lzIA=="
                     76: --Multibyte String --
                     77: string(16) "5pel5pys6Kqe44OG"
                     78: 
                     79: **-- Offset is: -20 --**
                     80: -- ASCII String --
                     81: string(8) "SXMgYQ=="
                     82: --Multibyte String --
                     83: string(16) "5pys6Kqe44OG44Kt"
                     84: 
                     85: **-- Offset is: -10 --**
                     86: -- ASCII String --
                     87: string(8) "aXNoIA=="
                     88: --Multibyte String --
                     89: string(8) "MTIzNA=="
                     90: 
                     91: **-- Offset is: 0 --**
                     92: -- ASCII String --
                     93: string(8) "K0lzIA=="
                     94: --Multibyte String --
                     95: string(16) "5pel5pys6Kqe44OG"
                     96: 
                     97: **-- Offset is: 10 --**
                     98: -- ASCII String --
                     99: string(8) "bGlzaA=="
                    100: --Multibyte String --
                    101: string(8) "MDEyMw=="
                    102: 
                    103: **-- Offset is: 20 --**
                    104: -- ASCII String --
                    105: string(4) "Zw=="
                    106: --Multibyte String --
                    107: string(4) "44CC"
                    108: 
                    109: **-- Offset is: 30 --**
                    110: -- ASCII String --
                    111: string(0) ""
                    112: --Multibyte String --
                    113: string(0) ""
                    114: 
                    115: **-- Offset is: 40 --**
                    116: -- ASCII String --
                    117: string(0) ""
                    118: --Multibyte String --
                    119: string(0) ""
                    120: 
                    121: **-- Offset is: 50 --**
                    122: -- ASCII String --
                    123: string(0) ""
                    124: --Multibyte String --
                    125: string(0) ""
                    126: 
                    127: **-- Offset is: 60 --**
                    128: -- ASCII String --
                    129: string(0) ""
                    130: --Multibyte String --
                    131: string(0) ""
                    132: Done

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