iconv_strpos.phpt 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. --TEST--
  2. iconv_strpos()
  3. --EXTENSIONS--
  4. iconv
  5. --INI--
  6. iconv.internal_charset=ISO-8859-1
  7. --FILE--
  8. <?php
  9. function foo($haystk, $needle, $offset, $to_charset = false, $from_charset = false)
  10. {
  11. if ($from_charset !== false) {
  12. $haystk = iconv($from_charset, $to_charset, $haystk);
  13. }
  14. try {
  15. var_dump(strpos($haystk, $needle, $offset));
  16. } catch (ValueError $exception) {
  17. echo $exception->getMessage() . "\n";
  18. }
  19. try {
  20. if ($to_charset !== false) {
  21. var_dump(iconv_strpos($haystk, $needle, $offset, $to_charset));
  22. } else {
  23. var_dump(iconv_strpos($haystk, $needle, $offset));
  24. }
  25. } catch (ValueError $exception) {
  26. echo $exception->getMessage() . "\n";
  27. }
  28. }
  29. foo("abecdbcdabef", "bcd", -1);
  30. foo("abecdbcdabef", "bcd", -7);
  31. foo("abecdbcdabef", "bcd", 12);
  32. foo("abecdbcdabef", "bcd", 100000);
  33. foo("abcabcabcdabcababcdabc", "bcd", 0);
  34. foo("abcabcabcdabcababcdabc", "bcd", 10);
  35. foo(str_repeat("abcab", 60)."abcdb".str_repeat("adabc", 60), "abcd", 0);
  36. foo(str_repeat("あいうえお", 30)."いうおえあ".str_repeat("あいえおう", 30), "うお", 0, "EUC-JP");
  37. $str = str_repeat("あいうえお", 60).'$'.str_repeat("あいえおう", 60);
  38. foo($str, '$', 0, "ISO-2022-JP", "EUC-JP");
  39. var_dump(iconv_strpos("string", ""));
  40. var_dump(iconv_strpos("", "string"));
  41. ?>
  42. --EXPECT--
  43. bool(false)
  44. bool(false)
  45. int(5)
  46. int(5)
  47. bool(false)
  48. bool(false)
  49. strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
  50. iconv_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
  51. int(7)
  52. int(7)
  53. int(16)
  54. int(16)
  55. int(300)
  56. int(300)
  57. int(302)
  58. int(151)
  59. int(1)
  60. int(300)
  61. bool(false)
  62. bool(false)