Annotation of embedaddon/php/ext/mbstring/tests/mb_substr_variation7.phpt, revision 1.1

1.1     ! misho       1: --TEST--
        !             2: Test mb_substr() function : usage variations - pass different integers to $length 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 $length 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: //Japanese string, 21 characters
        !            26: $string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
        !            27: 
        !            28: /*
        !            29:  * Loop through integers as multiples of ten for $offset argument
        !            30:  * 60 is larger than *BYTE* count for $string_mb
        !            31:  */
        !            32: for ($i = -60; $i <= 60; $i += 10) {
        !            33:        if (@$a || @$b) {
        !            34:                $a = null;
        !            35:                $b = null;
        !            36:        }
        !            37:        echo "\n**-- Offset is: $i --**\n";
        !            38:        echo "-- ASCII String --\n";
        !            39:        $a = mb_substr($string_ascii, 1, $i);
        !            40:        if ($a !== false) {
        !            41:           var_dump(bin2hex($a));
        !            42:        }
        !            43:        else {
        !            44:           var_dump($a);
        !            45:        }                       
        !            46:        echo "--Multibyte String --\n";
        !            47:        $b = mb_substr($string_mb, 1, $i, 'UTF-8');
        !            48:        if (strlen($a) == mb_strlen($b, 'UTF-8')) { // should return same length
        !            49:                var_dump(bin2hex($b));
        !            50:        } else {
        !            51:                echo "Difference in length of ASCII string and multibyte string\n";
        !            52:        }
        !            53:        
        !            54: }
        !            55: 
        !            56: echo "Done";
        !            57: ?>
        !            58: --EXPECT--
        !            59: *** Testing mb_substr() : usage variations ***
        !            60: 
        !            61: **-- Offset is: -60 --**
        !            62: -- ASCII String --
        !            63: string(0) ""
        !            64: --Multibyte String --
        !            65: string(0) ""
        !            66: 
        !            67: **-- Offset is: -50 --**
        !            68: -- ASCII String --
        !            69: string(0) ""
        !            70: --Multibyte String --
        !            71: string(0) ""
        !            72: 
        !            73: **-- Offset is: -40 --**
        !            74: -- ASCII String --
        !            75: string(0) ""
        !            76: --Multibyte String --
        !            77: string(0) ""
        !            78: 
        !            79: **-- Offset is: -30 --**
        !            80: -- ASCII String --
        !            81: string(0) ""
        !            82: --Multibyte String --
        !            83: string(0) ""
        !            84: 
        !            85: **-- Offset is: -20 --**
        !            86: -- ASCII String --
        !            87: string(0) ""
        !            88: --Multibyte String --
        !            89: string(0) ""
        !            90: 
        !            91: **-- Offset is: -10 --**
        !            92: -- ASCII String --
        !            93: string(20) "497320616e20456e676c"
        !            94: --Multibyte String --
        !            95: string(56) "e69cace8aa9ee38386e382ade382b9e38388e381a7e38199e3808230"
        !            96: 
        !            97: **-- Offset is: 0 --**
        !            98: -- ASCII String --
        !            99: string(0) ""
        !           100: --Multibyte String --
        !           101: string(0) ""
        !           102: 
        !           103: **-- Offset is: 10 --**
        !           104: -- ASCII String --
        !           105: string(20) "497320616e20456e676c"
        !           106: --Multibyte String --
        !           107: string(56) "e69cace8aa9ee38386e382ade382b9e38388e381a7e38199e3808230"
        !           108: 
        !           109: **-- Offset is: 20 --**
        !           110: -- ASCII String --
        !           111: string(40) "497320616e20456e676c69736820737472696e67"
        !           112: --Multibyte String --
        !           113: string(100) "e69cace8aa9ee38386e382ade382b9e38388e381a7e38199e380823031323334efbc95efbc96efbc97efbc98efbc99e38082"
        !           114: 
        !           115: **-- Offset is: 30 --**
        !           116: -- ASCII String --
        !           117: string(40) "497320616e20456e676c69736820737472696e67"
        !           118: --Multibyte String --
        !           119: string(100) "e69cace8aa9ee38386e382ade382b9e38388e381a7e38199e380823031323334efbc95efbc96efbc97efbc98efbc99e38082"
        !           120: 
        !           121: **-- Offset is: 40 --**
        !           122: -- ASCII String --
        !           123: string(40) "497320616e20456e676c69736820737472696e67"
        !           124: --Multibyte String --
        !           125: string(100) "e69cace8aa9ee38386e382ade382b9e38388e381a7e38199e380823031323334efbc95efbc96efbc97efbc98efbc99e38082"
        !           126: 
        !           127: **-- Offset is: 50 --**
        !           128: -- ASCII String --
        !           129: string(40) "497320616e20456e676c69736820737472696e67"
        !           130: --Multibyte String --
        !           131: string(100) "e69cace8aa9ee38386e382ade382b9e38388e381a7e38199e380823031323334efbc95efbc96efbc97efbc98efbc99e38082"
        !           132: 
        !           133: **-- Offset is: 60 --**
        !           134: -- ASCII String --
        !           135: string(40) "497320616e20456e676c69736820737472696e67"
        !           136: --Multibyte String --
        !           137: string(100) "e69cace8aa9ee38386e382ade382b9e38388e381a7e38199e380823031323334efbc95efbc96efbc97efbc98efbc99e38082"
        !           138: Done

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