xref: /PHP-8.3/ext/iconv/tests/iconv_strrpos.phpt (revision e9f783fc)
1--TEST--
2iconv_strrpos()
3--EXTENSIONS--
4iconv
5--INI--
6iconv.internal_charset=ISO-8859-1
7--FILE--
8<?php
9function my_error_handler($errno, $errmsg, $filename, $linenum)
10{
11    echo "$errno: $errmsg\n";
12}
13set_error_handler('my_error_handler');
14function 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}
27foo("abecdbcdabcdef", "bcd");
28foo(str_repeat("abcab", 60)."abcdb".str_repeat("adabc", 60), "abcd");
29foo(str_repeat("����������", 30)."����������".str_repeat("����������", 30), "����", "EUC-JP");
30
31for ($i = 0; $i <=6; ++$i) {
32    $str = str_repeat("����������", 60).str_repeat('$', $i).str_repeat("����������", 60);
33    foo($str, '$', "ISO-2022-JP", "EUC-JP");
34}
35
36var_dump(iconv_strrpos("string", ""));
37var_dump(iconv_strrpos("", "string"));
38
39?>
40--EXPECT--
41int(14)
42int(9)
43int(605)
44int(300)
45int(305)
46int(151)
47int(600)
48bool(false)
49int(601)
50int(300)
51int(602)
52int(301)
53int(603)
54int(302)
55int(604)
56int(303)
57int(605)
58int(304)
59int(606)
60int(305)
61bool(false)
62bool(false)
63