mb_substr_basic.phpt 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. --TEST--
  2. Test mb_substr() function : basic functionality
  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. --INI--
  9. mbstring.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. * Test Basic Functionality of mb_substr with ASCII characters and multibyte strings.
  18. */
  19. echo "*** Testing mb_substr() : basic functionality ***\n";
  20. $string_ascii = 'ABCDEF';
  21. //Japanese string in UTF-8
  22. $string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
  23. echo "\n-- ASCII string 1 --\n";
  24. var_dump(mb_substr($string_ascii, 3));
  25. echo "\n-- ASCII string 2 --\n";
  26. var_dump(mb_substr($string_ascii, 3, 5, 'ISO-8859-1'));
  27. echo "\n-- Multibyte string 1 --\n";
  28. $result_1 = mb_substr($string_mb, 2, 7);
  29. var_dump(base64_encode($result_1));
  30. echo "\n-- Multibyte string 2 --\n";
  31. $result_2 = mb_substr($string_mb, 2, 7, 'utf-8');
  32. var_dump(base64_encode($result_2));
  33. echo "Done";
  34. ?>
  35. --EXPECTF--
  36. *** Testing mb_substr() : basic functionality ***
  37. -- ASCII string 1 --
  38. string(3) "DEF"
  39. -- ASCII string 2 --
  40. string(3) "DEF"
  41. -- Multibyte string 1 --
  42. string(12) "peacrOiqng=="
  43. -- Multibyte string 2 --
  44. string(28) "6Kqe44OG44Kt44K544OI44Gn44GZ"
  45. Done