mb_substr_variation4.phpt 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. --TEST--
  2. Test mb_substr() function : usage variations - pass different integers to $start arg
  3. --EXTENSIONS--
  4. mbstring
  5. --FILE--
  6. <?php
  7. /*
  8. * Test how mb_substr() behaves when passed a range of integers as $start argument
  9. */
  10. echo "*** Testing mb_substr() : usage variations ***\n";
  11. mb_internal_encoding('UTF-8');
  12. $string_ascii = '+Is an English string'; //21 chars
  13. $string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII='); //21 chars
  14. /*
  15. * Loop through integers as multiples of ten for $offset argument
  16. * 60 is larger than *BYTE* count for $string_mb
  17. */
  18. for ($i = -60; $i <= 60; $i += 10) {
  19. if (@$a || @$b) {
  20. $a = null;
  21. $b = null;
  22. }
  23. echo "\n**-- Offset is: $i --**\n";
  24. echo "-- ASCII String --\n";
  25. $a = mb_substr($string_ascii, $i, 4);
  26. var_dump(base64_encode($a));
  27. echo "--Multibyte String --\n";
  28. $b = mb_substr($string_mb, $i, 4, 'UTF-8');
  29. if (strlen($a) == mb_strlen($b, 'UTF-8')) { // should return same length
  30. var_dump(base64_encode($b));
  31. } else {
  32. echo "Difference in length of ASCII string and multibyte string\n";
  33. }
  34. }
  35. echo "Done";
  36. ?>
  37. --EXPECT--
  38. *** Testing mb_substr() : usage variations ***
  39. **-- Offset is: -60 --**
  40. -- ASCII String --
  41. string(8) "K0lzIA=="
  42. --Multibyte String --
  43. string(16) "5pel5pys6Kqe44OG"
  44. **-- Offset is: -50 --**
  45. -- ASCII String --
  46. string(8) "K0lzIA=="
  47. --Multibyte String --
  48. string(16) "5pel5pys6Kqe44OG"
  49. **-- Offset is: -40 --**
  50. -- ASCII String --
  51. string(8) "K0lzIA=="
  52. --Multibyte String --
  53. string(16) "5pel5pys6Kqe44OG"
  54. **-- Offset is: -30 --**
  55. -- ASCII String --
  56. string(8) "K0lzIA=="
  57. --Multibyte String --
  58. string(16) "5pel5pys6Kqe44OG"
  59. **-- Offset is: -20 --**
  60. -- ASCII String --
  61. string(8) "SXMgYQ=="
  62. --Multibyte String --
  63. string(16) "5pys6Kqe44OG44Kt"
  64. **-- Offset is: -10 --**
  65. -- ASCII String --
  66. string(8) "aXNoIA=="
  67. --Multibyte String --
  68. string(8) "MTIzNA=="
  69. **-- Offset is: 0 --**
  70. -- ASCII String --
  71. string(8) "K0lzIA=="
  72. --Multibyte String --
  73. string(16) "5pel5pys6Kqe44OG"
  74. **-- Offset is: 10 --**
  75. -- ASCII String --
  76. string(8) "bGlzaA=="
  77. --Multibyte String --
  78. string(8) "MDEyMw=="
  79. **-- Offset is: 20 --**
  80. -- ASCII String --
  81. string(4) "Zw=="
  82. --Multibyte String --
  83. string(4) "44CC"
  84. **-- Offset is: 30 --**
  85. -- ASCII String --
  86. string(0) ""
  87. --Multibyte String --
  88. string(0) ""
  89. **-- Offset is: 40 --**
  90. -- ASCII String --
  91. string(0) ""
  92. --Multibyte String --
  93. string(0) ""
  94. **-- Offset is: 50 --**
  95. -- ASCII String --
  96. string(0) ""
  97. --Multibyte String --
  98. string(0) ""
  99. **-- Offset is: 60 --**
  100. -- ASCII String --
  101. string(0) ""
  102. --Multibyte String --
  103. string(0) ""
  104. Done