Annotation of embedaddon/php/ext/mbstring/tests/mb_substr_variation6.phpt, revision 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:        if ($a !== false) {
        !            40:           var_dump(bin2hex($a));
        !            41:        }
        !            42:        else {
        !            43:           var_dump($a);
        !            44:        }               
        !            45:        echo "--Multibyte String --\n";
        !            46:        $b = mb_substr($string_mb, $i, 4, 'UTF-8');
        !            47:        if (strlen($a) == mb_strlen($b, 'UTF-8')) { // should return same length
        !            48:                var_dump(bin2hex($b));
        !            49:        } else {
        !            50:                echo "Difference in length of ASCII string and multibyte string\n";
        !            51:        }
        !            52:        
        !            53: }
        !            54: 
        !            55: echo "Done";
        !            56: ?>
        !            57: --EXPECT--
        !            58: *** Testing mb_substr() : usage variations ***
        !            59: 
        !            60: **-- Offset is: -60 --**
        !            61: -- ASCII String --
        !            62: string(8) "2b497320"
        !            63: --Multibyte String --
        !            64: string(24) "e697a5e69cace8aa9ee38386"
        !            65: 
        !            66: **-- Offset is: -50 --**
        !            67: -- ASCII String --
        !            68: string(8) "2b497320"
        !            69: --Multibyte String --
        !            70: string(24) "e697a5e69cace8aa9ee38386"
        !            71: 
        !            72: **-- Offset is: -40 --**
        !            73: -- ASCII String --
        !            74: string(8) "2b497320"
        !            75: --Multibyte String --
        !            76: string(24) "e697a5e69cace8aa9ee38386"
        !            77: 
        !            78: **-- Offset is: -30 --**
        !            79: -- ASCII String --
        !            80: string(8) "2b497320"
        !            81: --Multibyte String --
        !            82: string(24) "e697a5e69cace8aa9ee38386"
        !            83: 
        !            84: **-- Offset is: -20 --**
        !            85: -- ASCII String --
        !            86: string(8) "49732061"
        !            87: --Multibyte String --
        !            88: string(24) "e69cace8aa9ee38386e382ad"
        !            89: 
        !            90: **-- Offset is: -10 --**
        !            91: -- ASCII String --
        !            92: string(8) "69736820"
        !            93: --Multibyte String --
        !            94: string(8) "31323334"
        !            95: 
        !            96: **-- Offset is: 0 --**
        !            97: -- ASCII String --
        !            98: string(8) "2b497320"
        !            99: --Multibyte String --
        !           100: string(24) "e697a5e69cace8aa9ee38386"
        !           101: 
        !           102: **-- Offset is: 10 --**
        !           103: -- ASCII String --
        !           104: string(8) "6c697368"
        !           105: --Multibyte String --
        !           106: string(8) "30313233"
        !           107: 
        !           108: **-- Offset is: 20 --**
        !           109: -- ASCII String --
        !           110: string(2) "67"
        !           111: --Multibyte String --
        !           112: string(6) "e38082"
        !           113: 
        !           114: **-- Offset is: 30 --**
        !           115: -- ASCII String --
        !           116: string(0) ""
        !           117: --Multibyte String --
        !           118: string(0) ""
        !           119: 
        !           120: **-- Offset is: 40 --**
        !           121: -- ASCII String --
        !           122: string(0) ""
        !           123: --Multibyte String --
        !           124: string(0) ""
        !           125: 
        !           126: **-- Offset is: 50 --**
        !           127: -- ASCII String --
        !           128: string(0) ""
        !           129: --Multibyte String --
        !           130: string(0) ""
        !           131: 
        !           132: **-- Offset is: 60 --**
        !           133: -- ASCII String --
        !           134: string(0) ""
        !           135: --Multibyte String --
        !           136: string(0) ""
        !           137: Done

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