xref: /PHP-8.4/ext/iconv/tests/iconv_strpos.phpt (revision e9f783fc)
1--TEST--
2iconv_strpos()
3--EXTENSIONS--
4iconv
5--INI--
6iconv.internal_charset=ISO-8859-1
7--FILE--
8<?php
9function 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}
29foo("abecdbcdabef", "bcd", -1);
30foo("abecdbcdabef", "bcd", -7);
31foo("abecdbcdabef", "bcd", 12);
32foo("abecdbcdabef", "bcd", 100000);
33foo("abcabcabcdabcababcdabc", "bcd", 0);
34foo("abcabcabcdabcababcdabc", "bcd", 10);
35foo(str_repeat("abcab", 60)."abcdb".str_repeat("adabc", 60), "abcd", 0);
36foo(str_repeat("����������", 30)."����������".str_repeat("����������", 30), "����", 0, "EUC-JP");
37$str = str_repeat("����������", 60).'$'.str_repeat("����������", 60);
38foo($str, '$', 0, "ISO-2022-JP", "EUC-JP");
39
40var_dump(iconv_strpos("string", ""));
41var_dump(iconv_strpos("", "string"));
42
43?>
44--EXPECT--
45bool(false)
46bool(false)
47int(5)
48int(5)
49bool(false)
50bool(false)
51strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
52iconv_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
53int(7)
54int(7)
55int(16)
56int(16)
57int(300)
58int(300)
59int(302)
60int(151)
61int(1)
62int(300)
63bool(false)
64bool(false)
65