xref: /PHP-5.4/ext/mbstring/tests/mb_stripos.phpt (revision 4a78652f)
1--TEST--
2mb_stripos()
3--SKIPIF--
4<?php
5extension_loaded('mbstring') or die('skip');
6function_exists('mb_stripos') or die("skip mb_stripos() is not available in this build");
7?>
8--FILE--
9<?php
10// TODO: Add more encodings
11
12//$debug=true;
13ini_set('include_path','.');
14include_once('common.inc');
15
16
17// Test string
18$euc_jp = b'0123����ʸ��������ܸ�Ǥ���EUC-JP��ȤäƤ��ޤ���0123���ܸ�����ݽ�����';
19
20// EUC-JP - With encoding parameter
21mb_internal_encoding('UTF-8') or print("mb_internal_encoding() failed\n");
22
23echo  "== POSITIVE OFFSET ==\n";
24print  mb_stripos($euc_jp,b'���ܸ�', 0, 'EUC-JP') . "\n";
25print  mb_stripos($euc_jp, b'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,b'���ܸ�', 15, 'EUC-JP') . "\n";
29print  mb_stripos($euc_jp, b'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// Negative offset
34// Note: PHP Warning - offset is negative.
35// Note: For offset(-15). It does not return position of latter string. (ie the same result as -50)
36echo "== NEGATIVE OFFSET ==\n";
37$r = mb_stripos($euc_jp,b'���ܸ�', -15, 'EUC-JP');
38($r === FALSE) ? print "OK_NEGATIVE_OFFSET\n" : print "NG_NEGATIVE_OFFSET\n";
39$r = mb_stripos($euc_jp, b'0', -15,     'EUC-JP');
40($r === FALSE) ? print "OK_NEGATIVE_OFFSET\n" : print "NG_NEGATIVE_OFFSET\n";
41$r = mb_stripos($euc_jp, 3, -15,       'EUC-JP');
42($r === FALSE) ? print "OK_NEGATIVE_OFFSET\n" : print "NG_NEGATIVE_OFFSET\n";
43$r = mb_stripos($euc_jp, 0, -15,       'EUC-JP');
44($r === FALSE) ? print "OK_NEGATIVE_OFFSET\n" : print "NG_NEGATIVE_OFFSET\n";
45$r = mb_stripos($euc_jp,b'���ܸ�', -50, 'EUC-JP');
46($r === FALSE) ? print "OK_NEGATIVE_OFFSET\n" : print "NG_NEGATIVE_OFFSET\n";
47$r = mb_stripos($euc_jp, b'0', -50,     'EUC-JP');
48($r === FALSE) ? print "OK_NEGATIVE_OFFSET\n" : print "NG_NEGATIVE_OFFSET\n";
49$r = mb_stripos($euc_jp, 3, -50,       'EUC-JP');
50($r === FALSE) ? print "OK_NEGATIVE_OFFSET\n" : print "NG_NEGATIVE_OFFSET\n";
51$r = mb_stripos($euc_jp, 0, -50,       'EUC-JP');
52($r === FALSE) ? print "OK_NEGATIVE_OFFSET\n" : print "NG_NEGATIVE_OFFSET\n";
53
54// Out of range - should return false
55print ("== OUT OF RANGE ==\n");
56$r =  mb_stripos($euc_jp,b'���ܸ�', 40, 'EUC-JP');
57($r === FALSE) ? print "OK_OUT_RANGE\n"     : print "NG_OUT_RANGE\n";
58$r =  mb_stripos($euc_jp, b'0', 40,     'EUC-JP');
59($r === FALSE) ? print "OK_OUT_RANGE\n"     : print "NG_OUT_RANGE\n";
60$r =  mb_stripos($euc_jp, 3, 40,       'EUC-JP');
61($r === FALSE) ? print "OK_OUT_RANGE\n"     : print "NG_OUT_RANGE\n";
62$r =   mb_stripos($euc_jp, 0, 40,       'EUC-JP');
63($r === FALSE) ? print "OK_OUT_RANGE\n"     : print "NG_OUT_RANGE\n";
64// Note: Returned NULL string
65// echo gettype($r). ' val '. $r ."\n";
66
67
68// Non-existent
69echo "== NON-EXISTENT ==\n";
70$r = mb_stripos($euc_jp, b'�ڹ��', 0, 'EUC-JP');
71($r === FALSE) ? print "OK_STR\n"     : print "NG_STR\n";
72$r = mb_stripos($euc_jp, b"\n",     0, 'EUC-JP');
73($r === FALSE) ? print "OK_NEWLINE\n" : print "NG_NEWLINE\n";
74
75
76// EUC-JP - No encoding parameter
77echo "== NO ENCODING PARAMETER ==\n";
78mb_internal_encoding('EUC-JP')  or print("mb_internal_encoding() failed\n");
79
80print  mb_stripos($euc_jp,b'���ܸ�', 0) . "\n";
81print  mb_stripos($euc_jp, b'0', 0) . "\n";
82print  mb_stripos($euc_jp, 3, 0) . "\n";
83print  mb_stripos($euc_jp, 0, 0) . "\n";
84
85$r = mb_stripos($euc_jp,b'�ڹ��', 0);
86($r === FALSE) ? print "OK_STR\n"     : print "NG_STR\n";
87$r = mb_stripos($euc_jp,b"\n", 0);
88($r === FALSE) ? print "OK_NEWLINE\n" : print "NG_NEWLINE\n";
89
90// EUC-JP - No offset and encoding parameter
91echo "== NO OFFSET AND ENCODING PARAMETER ==\n";
92mb_internal_encoding('EUC-JP')  or print("mb_internal_encoding() failed\n");
93
94print  mb_stripos($euc_jp,b'���ܸ�') . "\n";
95print  mb_stripos($euc_jp, b'0') . "\n";
96print  mb_stripos($euc_jp, 3) . "\n";
97print  mb_stripos($euc_jp, 0) . "\n";
98
99$r = mb_stripos($euc_jp,b'�ڹ��');
100($r === FALSE) ? print "OK_STR\n"     : print "NG_STR\n";
101$r = mb_stripos($euc_jp,b"\n");
102($r === FALSE) ? print "OK_NEWLINE\n" : print "NG_NEWLINE\n";
103
104
105// Invalid Parameters
106echo "== INVALID PARAMETER TEST ==\n";
107
108$r = mb_stripos($euc_jp,'','EUC-JP');
109($r === FALSE) ? print("OK_NULL\n") : print("NG_NULL\n");
110$r = mb_stripos($euc_jp, $t_ary, 'EUC-JP');
111($r === FALSE) ? print("OK_ARRAY\n") : print("NG_ARRAY\n");
112$r = mb_stripos($euc_jp, $t_obj, 'EUC-JP');
113($r === FALSE) ? print("OK_OBJECT\n") : print("NG_OBJECT\n");
114$r = mb_stripos($euc_jp, $t_obj, 'BAD_ENCODING');
115($r === FALSE) ? print("OK_BAD_ENCODING\n") : print("NG_BAD_ENCODING\n");
116
117
118?>
119
120--EXPECT--
121== POSITIVE OFFSET ==
12210
1230
1243
1250
12634
12730
12833
12930
130== NEGATIVE OFFSET ==
131ERR: Warning
132OK_NEGATIVE_OFFSET
133ERR: Warning
134OK_NEGATIVE_OFFSET
135ERR: Warning
136OK_NEGATIVE_OFFSET
137ERR: Warning
138OK_NEGATIVE_OFFSET
139ERR: Warning
140OK_NEGATIVE_OFFSET
141ERR: Warning
142OK_NEGATIVE_OFFSET
143ERR: Warning
144OK_NEGATIVE_OFFSET
145ERR: Warning
146OK_NEGATIVE_OFFSET
147== OUT OF RANGE ==
148OK_OUT_RANGE
149OK_OUT_RANGE
150OK_OUT_RANGE
151OK_OUT_RANGE
152== NON-EXISTENT ==
153OK_STR
154OK_NEWLINE
155== NO ENCODING PARAMETER ==
15610
1570
1583
1590
160OK_STR
161OK_NEWLINE
162== NO OFFSET AND ENCODING PARAMETER ==
16310
1640
1653
1660
167OK_STR
168OK_NEWLINE
169== INVALID PARAMETER TEST ==
170ERR: Warning
171OK_NULL
172ERR: Warning
173OK_ARRAY
174ERR: Warning
175OK_OBJECT
176ERR: Warning
177OK_BAD_ENCODING
178
179