1--TEST--
2Test iconv_strpos() function : basic functionality
3--SKIPIF--
4<?php
5extension_loaded('iconv') or die('skip');
6function_exists('iconv_strpos') or die("skip iconv_strpos() is not available in this build");
7?>
8--FILE--
9<?php
10/* Prototype  : int iconv_strpos(string haystack, string needle [, int offset [, string charset]])
11 * Description: Find position of first occurrence of a string within another
12 * Source code: ext/iconv/iconv.c
13 */
14
15/*
16 * Test basic functionality of iconv_strpos with ASCII and multibyte characters
17 */
18
19echo "*** Testing iconv_strpos() : basic functionality***\n";
20
21iconv_set_encoding("internal_encoding", "UTF-8");
22
23$string_ascii = b'abc def';
24//Japanese string in UTF-8
25$string_mb = base64_decode(b'5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
26
27echo "\n-- ASCII string 1 --\n";
28var_dump(iconv_strpos($string_ascii, b'd', 2, 'ISO-8859-1'));
29
30echo "\n-- ASCII string 2 --\n";
31var_dump(iconv_strpos($string_ascii, b'123'));
32
33echo "\n-- Multibyte string 1 --\n";
34$needle1 = base64_decode('5pel5pys6Kqe');
35var_dump(iconv_strpos($string_mb, $needle1));
36
37echo "\n-- Multibyte string 2 --\n";
38$needle2 = base64_decode(b"44GT44KT44Gr44Gh44Gv44CB5LiW55WM");
39var_dump(iconv_strpos($string_mb, $needle2));
40
41echo "Done";
42?>
43--EXPECTF--
44*** Testing iconv_strpos() : basic functionality***
45
46-- ASCII string 1 --
47int(4)
48
49-- ASCII string 2 --
50bool(false)
51
52-- Multibyte string 1 --
53int(0)
54
55-- Multibyte string 2 --
56bool(false)
57Done