iconv_substr.phpt 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. --TEST--
  2. iconv_substr()
  3. --EXTENSIONS--
  4. iconv
  5. --INI--
  6. iconv.internal_charset=ISO-8859-1
  7. --FILE--
  8. <?php
  9. function hexdump($str) {
  10. $len = strlen($str);
  11. for ($i = 0; $i < $len; ++$i) {
  12. printf("%02x", ord($str[$i]));
  13. }
  14. print "\n";
  15. }
  16. function foo($str, $offset, $len, $charset) {
  17. hexdump(substr($str, $offset, $len));
  18. hexdump(iconv_substr($str, $offset, $len, $charset));
  19. }
  20. function bar($str, $offset, $len = false) {
  21. if (is_bool($len)) {
  22. var_dump(substr($str, $offset));
  23. var_dump(iconv_substr($str, $offset));
  24. } else {
  25. var_dump(substr($str, $offset, $len));
  26. var_dump(iconv_substr($str, $offset, $len));
  27. }
  28. }
  29. foo("abcdefghijklmnopqrstuvwxyz", 5, 7, "ASCII");
  30. foo("あいうえおかきくけこさしす", 5, 7, "EUC-JP");
  31. bar("This is a test", 100000);
  32. bar("This is a test", 0, 100000);
  33. bar("This is a test", -3);
  34. bar("This is a test", -3, null);
  35. bar("This is a test", 0, -9);
  36. bar("This is a test", 0, -100000);
  37. bar("This is a test", -9, -100000);
  38. var_dump(iconv("ISO-2022-JP", "EUC-JP", iconv_substr(iconv("EUC-JP", "ISO-2022-JP", "こんにちは ISO-2022-JP"), 3, 8, "ISO-2022-JP")));
  39. ?>
  40. --EXPECT--
  41. 666768696a6b6c
  42. 666768696a6b6c
  43. a6a4a8a4aaa4ab
  44. a4aba4ada4afa4b1a4b3a4b5a4b7
  45. string(0) ""
  46. string(0) ""
  47. string(14) "This is a test"
  48. string(14) "This is a test"
  49. string(3) "est"
  50. string(3) "est"
  51. string(3) "est"
  52. string(3) "est"
  53. string(5) "This "
  54. string(5) "This "
  55. string(0) ""
  56. string(0) ""
  57. string(0) ""
  58. string(0) ""
  59. string(10) "ちは ISO-2"