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