xref: /PHP-7.1/ext/iconv/tests/iconv_strpos.phpt (revision 570bbed9)
1--TEST--
2iconv_strpos()
3--SKIPIF--
4<?php extension_loaded('iconv') or die('skip iconv extension is not available'); ?>
5--INI--
6iconv.internal_charset=ISO-8859-1
7--FILE--
8<?php
9function my_error_handler($errno, $errmsg, $filename, $linenum, $vars)
10{
11	echo "$errno: $errmsg\n";
12}
13set_error_handler('my_error_handler');
14function foo($haystk, $needle, $offset, $to_charset = false, $from_charset = false)
15{
16	if ($from_charset !== false) {
17		$haystk = iconv($from_charset, $to_charset, $haystk);
18	}
19	var_dump(strpos($haystk, $needle, $offset));
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}
26foo("abecdbcdabef", "bcd", -1);
27foo("abecdbcdabef", "bcd", -7);
28foo("abecdbcdabef", "bcd", 100000);
29foo("abcabcabcdabcababcdabc", "bcd", 0);
30foo("abcabcabcdabcababcdabc", "bcd", 10);
31foo(str_repeat("abcab", 60)."abcdb".str_repeat("adabc", 60), "abcd", 0);
32foo(str_repeat("����������", 30)."����������".str_repeat("����������", 30), "����", 0, "EUC-JP");
33$str = str_repeat("����������", 60).'$'.str_repeat("����������", 60);
34foo($str, '$', 0, "ISO-2022-JP", "EUC-JP");
35
36var_dump(iconv_strpos("string", ""));
37var_dump(iconv_strpos("", "string"));
38
39?>
40--EXPECTF--
41bool(false)
42bool(false)
43int(5)
44int(5)
452: %s
46bool(false)
47bool(false)
48int(7)
49int(7)
50int(16)
51int(16)
52int(300)
53int(300)
54int(302)
55int(151)
56int(1)
57int(300)
58bool(false)
59bool(false)
60