xref: /PHP-7.4/ext/mbstring/tests/mb_stripos.phpt (revision 4bd18db8)
1--TEST--
2mb_stripos()
3--SKIPIF--
4<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?>
5--FILE--
6<?php
7// TODO: Add more encodings
8
9ini_set('include_path','.');
10include_once('common.inc');
11
12
13// Test string
14$euc_jp = '0123����ʸ��������ܸ�Ǥ���EUC-JP��ȤäƤ��ޤ���0123���ܸ�����ݽ�����';
15
16$slen = mb_strlen($euc_jp, 'EUC-JP');
17echo "String len: $slen\n";
18
19// EUC-JP - With encoding parameter
20mb_internal_encoding('UTF-8') or print("mb_internal_encoding() failed\n");
21
22echo  "== POSITIVE OFFSET ==\n";
23
24print  mb_stripos($euc_jp, '���ܸ�', 0, 'EUC-JP') . "\n";
25print  mb_stripos($euc_jp, '0', 0,     'EUC-JP') . "\n";
26print  mb_stripos($euc_jp, 3, 0,       'EUC-JP') . "\n";
27print  mb_stripos($euc_jp, 0, 0,       'EUC-JP') . "\n";
28print  mb_stripos($euc_jp, '���ܸ�', 15, 'EUC-JP') . "\n";
29print  mb_stripos($euc_jp, '0', 15,     'EUC-JP') . "\n";
30print  mb_stripos($euc_jp, 3, 15,       'EUC-JP') . "\n";
31print  mb_stripos($euc_jp, 0, 15,       'EUC-JP') . "\n";
32
33
34// Negative offset
35echo "== NEGATIVE OFFSET ==\n";
36
37print mb_stripos($euc_jp, '���ܸ�', -15, 'EUC-JP') . "\n";
38print mb_stripos($euc_jp, '0', -15,     'EUC-JP') . "\n";
39print mb_stripos($euc_jp, 3, -15,       'EUC-JP') . "\n";
40print mb_stripos($euc_jp, 0, -15,       'EUC-JP') . "\n";
41print mb_stripos($euc_jp, 0, -43,       'EUC-JP') . "\n";
42
43
44// Invalid offset - should return false with warning
45print ("== INVALID OFFSET ==\n");
46
47$r =  mb_stripos($euc_jp, '���ܸ�', 44, 'EUC-JP');
48($r === FALSE) ? print "OK_INVALID_OFFSET\n"     : print "NG_INVALID_OFFSET\n";
49$r =  mb_stripos($euc_jp, '���ܸ�', 50, 'EUC-JP');
50($r === FALSE) ? print "OK_INVALID_OFFSET\n"     : print "NG_INVALID_OFFSET\n";
51$r =  mb_stripos($euc_jp, '0', 50,     'EUC-JP');
52($r === FALSE) ? print "OK_INVALID_OFFSET\n"     : print "NG_INVALID_OFFSET\n";
53$r =  mb_stripos($euc_jp, 3, 50,       'EUC-JP');
54($r === FALSE) ? print "OK_INVALID_OFFSET\n"     : print "NG_INVALID_OFFSET\n";
55$r =   mb_stripos($euc_jp, 0, 50,       'EUC-JP');
56($r === FALSE) ? print "OK_INVALID_OFFSET\n"     : print "NG_INVALID_OFFSET\n";
57$r = mb_stripos($euc_jp, '���ܸ�', -50, 'EUC-JP');
58($r === FALSE) ? print "OK_INVALID_OFFSET\n"     : print "NG_INVALID_OFFSET\n";
59$r = mb_stripos($euc_jp, '0', -50,     'EUC-JP');
60($r === FALSE) ? print "OK_INVALID_OFFSET\n"     : print "NG_INVALID_OFFSET\n";
61$r = mb_stripos($euc_jp, 3, -50,       'EUC-JP');
62($r === FALSE) ? print "OK_INVALID_OFFSET\n"     : print "NG_INVALID_OFFSET\n";
63$r = mb_stripos($euc_jp, 0, -50,       'EUC-JP');
64($r === FALSE) ? print "OK_INVALID_OFFSET\n"     : print "NG_INVALID_OFFSET\n";
65$r = mb_stripos($euc_jp, 0, -44,       'EUC-JP');
66($r === FALSE) ? print "OK_INVALID_OFFSET\n"     : print "NG_INVALID_OFFSET\n";
67
68// Out of range - should return false
69print ("== OUT OF RANGE ==\n");
70
71$r =  mb_stripos($euc_jp, '���ܸ�', 40, 'EUC-JP');
72($r === FALSE) ? print "OK_OUT_RANGE\n"     : print "NG_OUT_RANGE\n";
73$r =  mb_stripos($euc_jp, '0', 40,     'EUC-JP');
74($r === FALSE) ? print "OK_OUT_RANGE\n"     : print "NG_OUT_RANGE\n";
75$r =  mb_stripos($euc_jp, 3, 40,       'EUC-JP');
76($r === FALSE) ? print "OK_OUT_RANGE\n"     : print "NG_OUT_RANGE\n";
77$r =   mb_stripos($euc_jp, 0, 40,       'EUC-JP');
78($r === FALSE) ? print "OK_OUT_RANGE\n"     : print "NG_OUT_RANGE\n";
79$r =  mb_stripos($euc_jp, '���ܸ�', -3, 'EUC-JP');
80($r === FALSE) ? print "OK_OUT_RANGE\n"     : print "NG_OUT_RANGE\n";
81$r =  mb_stripos($euc_jp, '0', -3,     'EUC-JP');
82($r === FALSE) ? print "OK_OUT_RANGE\n"     : print "NG_OUT_RANGE\n";
83$r =  mb_stripos($euc_jp, 3, -3,       'EUC-JP');
84($r === FALSE) ? print "OK_OUT_RANGE\n"     : print "NG_OUT_RANGE\n";
85$r =   mb_stripos($euc_jp, 0, -3,       'EUC-JP');
86($r === FALSE) ? print "OK_OUT_RANGE\n"     : print "NG_OUT_RANGE\n";
87
88
89// Non-existent
90echo "== NON-EXISTENT ==\n";
91
92$r = mb_stripos($euc_jp, '�ڹ��', 0, 'EUC-JP');
93($r === FALSE) ? print "OK_STR\n"     : print "NG_STR\n";
94$r = mb_stripos($euc_jp, "\n",     0, 'EUC-JP');
95($r === FALSE) ? print "OK_NEWLINE\n" : print "NG_NEWLINE\n";
96
97
98// EUC-JP - No encoding parameter
99echo "== NO ENCODING PARAMETER ==\n";
100
101mb_internal_encoding('EUC-JP')  or print("mb_internal_encoding() failed\n");
102
103print  mb_stripos($euc_jp, '���ܸ�', 0) . "\n";
104print  mb_stripos($euc_jp, '0', 0) . "\n";
105print  mb_stripos($euc_jp, 3, 0) . "\n";
106print  mb_stripos($euc_jp, 0, 0) . "\n";
107
108$r = mb_stripos($euc_jp, '�ڹ��', 0);
109($r === FALSE) ? print "OK_STR\n"     : print "NG_STR\n";
110$r = mb_stripos($euc_jp, "\n", 0);
111($r === FALSE) ? print "OK_NEWLINE\n" : print "NG_NEWLINE\n";
112
113// EUC-JP - No offset and encoding parameter
114echo "== NO OFFSET AND ENCODING PARAMETER ==\n";
115
116mb_internal_encoding('EUC-JP')  or print("mb_internal_encoding() failed\n");
117
118print  mb_stripos($euc_jp, '���ܸ�') . "\n";
119print  mb_stripos($euc_jp, '0') . "\n";
120print  mb_stripos($euc_jp, 3) . "\n";
121print  mb_stripos($euc_jp, 0) . "\n";
122
123$r = mb_stripos($euc_jp, '�ڹ��');
124($r === FALSE) ? print "OK_STR\n"     : print "NG_STR\n";
125$r = mb_stripos($euc_jp, "\n");
126($r === FALSE) ? print "OK_NEWLINE\n" : print "NG_NEWLINE\n";
127
128
129// Invalid Parameters
130echo "== INVALID PARAMETER TEST ==\n";
131
132$r = mb_stripos($euc_jp,'','EUC-JP');
133($r === NULL) ? print("OK_NULL\n") : print("NG_NULL\n");
134$r = mb_stripos($euc_jp, $t_ary, 'EUC-JP');
135($r === NULL) ? print("OK_ARRAY\n") : print("NG_ARRAY\n");
136$r = mb_stripos($euc_jp, $t_obj, 'EUC-JP');
137($r === NULL) ? print("OK_OBJECT\n") : print("NG_OBJECT\n");
138$r = mb_stripos($euc_jp, $t_obj, 'BAD_ENCODING');
139($r === NULL) ? print("OK_BAD_ENCODING\n") : print("NG_BAD_ENCODING\n");
140?>
141==DONE==
142--EXPECTF--
143String len: 43
144== POSITIVE OFFSET ==
14510
1460
1473
1480
14934
15030
15133
15230
153== NEGATIVE OFFSET ==
15434
15530
15633
15730
1580
159== INVALID OFFSET ==
160
161Warning: mb_stripos(): Offset not contained in string in %s on line %d
162OK_INVALID_OFFSET
163
164Warning: mb_stripos(): Offset not contained in string in %s on line %d
165OK_INVALID_OFFSET
166
167Warning: mb_stripos(): Offset not contained in string in %s on line %d
168OK_INVALID_OFFSET
169
170Warning: mb_stripos(): Offset not contained in string in %s on line %d
171OK_INVALID_OFFSET
172
173Warning: mb_stripos(): Offset not contained in string in %s on line %d
174OK_INVALID_OFFSET
175
176Warning: mb_stripos(): Offset not contained in string in %s on line %d
177OK_INVALID_OFFSET
178
179Warning: mb_stripos(): Offset not contained in string in %s on line %d
180OK_INVALID_OFFSET
181
182Warning: mb_stripos(): Offset not contained in string in %s on line %d
183OK_INVALID_OFFSET
184
185Warning: mb_stripos(): Offset not contained in string in %s on line %d
186OK_INVALID_OFFSET
187
188Warning: mb_stripos(): Offset not contained in string in %s on line %d
189OK_INVALID_OFFSET
190== OUT OF RANGE ==
191OK_OUT_RANGE
192OK_OUT_RANGE
193OK_OUT_RANGE
194OK_OUT_RANGE
195OK_OUT_RANGE
196OK_OUT_RANGE
197OK_OUT_RANGE
198OK_OUT_RANGE
199== NON-EXISTENT ==
200OK_STR
201OK_NEWLINE
202== NO ENCODING PARAMETER ==
20310
2040
2053
2060
207OK_STR
208OK_NEWLINE
209== NO OFFSET AND ENCODING PARAMETER ==
21010
2110
2123
2130
214OK_STR
215OK_NEWLINE
216== INVALID PARAMETER TEST ==
217
218Warning: mb_stripos() expects parameter 3 to be int, string given in %s on line %d
219OK_NULL
220
221Warning: mb_stripos() expects parameter 2 to be string, array given in %s on line %d
222OK_ARRAY
223
224Warning: mb_stripos() expects parameter 2 to be string, object given in %s on line %d
225OK_OBJECT
226
227Warning: mb_stripos() expects parameter 2 to be string, object given in %s on line %d
228OK_BAD_ENCODING
229==DONE==
230