Annotation of embedaddon/php/ext/iconv/tests/iconv_substr_basic.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test iconv_substr() function : basic functionality 
                      3: --SKIPIF--
                      4: <?php
                      5: extension_loaded('iconv') or die('skip');
                      6: function_exists('iconv_substr') or die("skip iconv_substr() is not available in this build");
                      7: ?>
                      8: --INI--
                      9: iconv.input_encoding=ISO-8859-1
                     10: iconv.internal_encoding=ISO-8859-1
                     11: iconv.output_encoding=ISO-8859-1
                     12: --FILE--
                     13: <?php
                     14: /* Prototype  : string iconv_substr(string str, int offset, [int length, string charset])
                     15:  * Description: Returns part of a string 
                     16:  * Source code: ext/iconv/iconv.c
                     17:  */
                     18: 
                     19: /*
                     20:  * Test Basic Functionality of iconv_substr with ASCII characters and multibyte strings.
                     21:  */
                     22: 
                     23: echo "*** Testing iconv_substr() : basic functionality ***\n";
                     24: 
                     25: $string_ascii = b'ABCDEF';
                     26: //Japanese string in UTF-8
                     27: $string_mb = base64_decode(b'5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
                     28: 
                     29: echo "\n-- ASCII string 1 --\n";
                     30: var_dump(bin2hex(iconv_substr($string_ascii, 3)));
                     31: 
                     32: echo "\n-- ASCII string 2 --\n";
                     33: var_dump(bin2hex(iconv_substr($string_ascii, 3, 5, 'ISO-8859-1')));
                     34: 
                     35: echo "\n-- Multibyte string 1 --\n";
                     36: $result_1 = iconv_substr($string_mb, 2, 7);
                     37: var_dump(bin2hex($result_1));
                     38: 
                     39: echo "\n-- Multibyte string 2 --\n";
                     40: $result_2 = iconv_substr($string_mb, 2, 7, 'utf-8');
                     41: var_dump(bin2hex($result_2));
                     42: 
                     43: echo "Done";
                     44: ?>
                     45: --EXPECT--
                     46: *** Testing iconv_substr() : basic functionality ***
                     47: 
                     48: -- ASCII string 1 --
                     49: string(6) "444546"
                     50: 
                     51: -- ASCII string 2 --
                     52: string(6) "444546"
                     53: 
                     54: -- Multibyte string 1 --
                     55: string(14) "a5e69cace8aa9e"
                     56: 
                     57: -- Multibyte string 2 --
                     58: string(42) "e8aa9ee38386e382ade382b9e38388e381a7e38199"
                     59: Done

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