iconv_strrpos.phpt 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. --TEST--
  2. iconv_strrpos()
  3. --EXTENSIONS--
  4. iconv
  5. --INI--
  6. iconv.internal_charset=ISO-8859-1
  7. --FILE--
  8. <?php
  9. function my_error_handler($errno, $errmsg, $filename, $linenum)
  10. {
  11. echo "$errno: $errmsg\n";
  12. }
  13. set_error_handler('my_error_handler');
  14. function foo($haystk, $needle, $to_charset = false, $from_charset = false)
  15. {
  16. if ($from_charset !== false) {
  17. $haystk = iconv($from_charset, $to_charset, $haystk);
  18. }
  19. if ($to_charset !== false) {
  20. var_dump(iconv_strlen($haystk, $to_charset));
  21. var_dump(iconv_strrpos($haystk, $needle, $to_charset));
  22. } else {
  23. var_dump(iconv_strlen($haystk));
  24. var_dump(iconv_strrpos($haystk, $needle));
  25. }
  26. }
  27. foo("abecdbcdabcdef", "bcd");
  28. foo(str_repeat("abcab", 60)."abcdb".str_repeat("adabc", 60), "abcd");
  29. foo(str_repeat("あいうえお", 30)."いうおえあ".str_repeat("あいえおう", 30), "うお", "EUC-JP");
  30. for ($i = 0; $i <=6; ++$i) {
  31. $str = str_repeat("あいうえお", 60).str_repeat('$', $i).str_repeat("あいえおう", 60);
  32. foo($str, '$', "ISO-2022-JP", "EUC-JP");
  33. }
  34. var_dump(iconv_strrpos("string", ""));
  35. var_dump(iconv_strrpos("", "string"));
  36. ?>
  37. --EXPECT--
  38. int(14)
  39. int(9)
  40. int(605)
  41. int(300)
  42. int(305)
  43. int(151)
  44. int(600)
  45. bool(false)
  46. int(601)
  47. int(300)
  48. int(602)
  49. int(301)
  50. int(603)
  51. int(302)
  52. int(604)
  53. int(303)
  54. int(605)
  55. int(304)
  56. int(606)
  57. int(305)
  58. bool(false)
  59. bool(false)