xref: /PHP-5.5/ext/iconv/tests/iconv_strpos.phpt (revision 7d7f8456)
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", 100000);
28foo("abcabcabcdabcababcdabc", "bcd", 0);
29foo("abcabcabcdabcababcdabc", "bcd", 10);
30foo(str_repeat("abcab", 60)."abcdb".str_repeat("adabc", 60), "abcd", 0);
31foo(str_repeat("����������", 30)."����������".str_repeat("����������", 30), "����", 0, "EUC-JP");
32$str = str_repeat("����������", 60).'$'.str_repeat("����������", 60);
33foo($str, '$', 0, "ISO-2022-JP", "EUC-JP");
34
35var_dump(iconv_strpos("string", ""));
36var_dump(iconv_strpos("", "string"));
37
38?>
39--EXPECTF--
402: %s
41bool(false)
422: %s
43bool(false)
442: %s
45bool(false)
46bool(false)
47int(7)
48int(7)
49int(16)
50int(16)
51int(300)
52int(300)
53int(302)
54int(151)
55int(1)
56int(300)
57bool(false)
58bool(false)
59