1--TEST-- 2mb_strpos() 3--SKIPIF-- 4<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?> 5--FILE-- 6<?php 7// TODO: Add more encodings 8 9//$debug=true; 10ini_set('include_path','.'); 11include_once('common.inc'); 12 13 14// Test string 15$euc_jp = b'0123����ʸ��������ܸ�Ǥ���EUC-JP��ȤäƤ��ޤ���0123���ܸ�����ݽ�����'; 16 17// EUC-JP - With encoding parameter 18mb_internal_encoding('UTF-8') or print("mb_internal_encoding() failed\n"); 19 20echo "== POSITIVE OFFSET ==\n"; 21print mb_strpos($euc_jp, b'���ܸ�', 0, 'EUC-JP') . "\n"; 22print mb_strpos($euc_jp, b'0', 0, 'EUC-JP') . "\n"; 23print mb_strpos($euc_jp, 3, 0, 'EUC-JP') . "\n"; 24print mb_strpos($euc_jp, 0, 0, 'EUC-JP') . "\n"; 25print mb_strpos($euc_jp, b'���ܸ�', 15, 'EUC-JP') . "\n"; 26print mb_strpos($euc_jp, b'0', 15, 'EUC-JP') . "\n"; 27print mb_strpos($euc_jp, 3, 15, 'EUC-JP') . "\n"; 28print mb_strpos($euc_jp, 0, 15, 'EUC-JP') . "\n"; 29 30// Negative offset 31// Note: PHP Warning - offset is negative. 32// Note: For offset(-15). It does not return position of latter string. (ie the same result as -50) 33echo "== NEGATIVE OFFSET ==\n"; 34$r = mb_strpos($euc_jp, b'���ܸ�', -15, 'EUC-JP'); 35($r === FALSE) ? print "OK_NEGATIVE_OFFSET\n" : print "NG_NEGATIVE_OFFSET\n"; 36$r = mb_strpos($euc_jp, b'0', -15, 'EUC-JP'); 37($r === FALSE) ? print "OK_NEGATIVE_OFFSET\n" : print "NG_NEGATIVE_OFFSET\n"; 38$r = mb_strpos($euc_jp, 3, -15, 'EUC-JP'); 39($r === FALSE) ? print "OK_NEGATIVE_OFFSET\n" : print "NG_NEGATIVE_OFFSET\n"; 40$r = mb_strpos($euc_jp, 0, -15, 'EUC-JP'); 41($r === FALSE) ? print "OK_NEGATIVE_OFFSET\n" : print "NG_NEGATIVE_OFFSET\n"; 42$r = mb_strpos($euc_jp, b'���ܸ�', -50, 'EUC-JP'); 43($r === FALSE) ? print "OK_NEGATIVE_OFFSET\n" : print "NG_NEGATIVE_OFFSET\n"; 44$r = mb_strpos($euc_jp, b'0', -50, 'EUC-JP'); 45($r === FALSE) ? print "OK_NEGATIVE_OFFSET\n" : print "NG_NEGATIVE_OFFSET\n"; 46$r = mb_strpos($euc_jp, 3, -50, 'EUC-JP'); 47($r === FALSE) ? print "OK_NEGATIVE_OFFSET\n" : print "NG_NEGATIVE_OFFSET\n"; 48$r = mb_strpos($euc_jp, 0, -50, 'EUC-JP'); 49($r === FALSE) ? print "OK_NEGATIVE_OFFSET\n" : print "NG_NEGATIVE_OFFSET\n"; 50 51// Out of range - should return false 52print ("== OUT OF RANGE ==\n"); 53$r = mb_strpos($euc_jp, b'���ܸ�', 40, 'EUC-JP'); 54($r === FALSE) ? print "OK_OUT_RANGE\n" : print "NG_OUT_RANGE\n"; 55$r = mb_strpos($euc_jp, b'0', 40, 'EUC-JP'); 56($r === FALSE) ? print "OK_OUT_RANGE\n" : print "NG_OUT_RANGE\n"; 57$r = mb_strpos($euc_jp, 3, 40, 'EUC-JP'); 58($r === FALSE) ? print "OK_OUT_RANGE\n" : print "NG_OUT_RANGE\n"; 59$r = mb_strpos($euc_jp, 0, 40, 'EUC-JP'); 60($r === FALSE) ? print "OK_OUT_RANGE\n" : print "NG_OUT_RANGE\n"; 61// Note: Returned NULL string 62// echo gettype($r). ' val '. $r ."\n"; 63 64 65// Non-existent 66echo "== NON-EXISTENT ==\n"; 67$r = mb_strpos($euc_jp, b'�ڹ��', 0, 'EUC-JP'); 68($r === FALSE) ? print "OK_STR\n" : print "NG_STR\n"; 69$r = mb_strpos($euc_jp, b"\n", 0, 'EUC-JP'); 70($r === FALSE) ? print "OK_NEWLINE\n" : print "NG_NEWLINE\n"; 71 72 73// EUC-JP - No encoding parameter 74echo "== NO ENCODING PARAMETER ==\n"; 75mb_internal_encoding('EUC-JP') or print("mb_internal_encoding() failed\n"); 76 77print mb_strpos($euc_jp, b'���ܸ�', 0) . "\n"; 78print mb_strpos($euc_jp, b'0', 0) . "\n"; 79print mb_strpos($euc_jp, 3, 0) . "\n"; 80print mb_strpos($euc_jp, 0, 0) . "\n"; 81 82$r = mb_strpos($euc_jp, b'�ڹ��', 0); 83($r === FALSE) ? print "OK_STR\n" : print "NG_STR\n"; 84$r = mb_strpos($euc_jp, b"\n", 0); 85($r === FALSE) ? print "OK_NEWLINE\n" : print "NG_NEWLINE\n"; 86 87// EUC-JP - No offset and encoding parameter 88echo "== NO OFFSET AND ENCODING PARAMETER ==\n"; 89mb_internal_encoding('EUC-JP') or print("mb_internal_encoding() failed\n"); 90 91print mb_strpos($euc_jp, b'���ܸ�') . "\n"; 92print mb_strpos($euc_jp, b'0') . "\n"; 93print mb_strpos($euc_jp, 3) . "\n"; 94print mb_strpos($euc_jp, 0) . "\n"; 95 96$r = mb_strpos($euc_jp, b'�ڹ��'); 97($r === FALSE) ? print "OK_STR\n" : print "NG_STR\n"; 98$r = mb_strpos($euc_jp, b"\n"); 99($r === FALSE) ? print "OK_NEWLINE\n" : print "NG_NEWLINE\n"; 100 101 102// Invalid Parameters 103echo "== INVALID PARAMETER TEST ==\n"; 104 105$r = mb_strpos($euc_jp,'','EUC-JP'); 106($r === FALSE) ? print("OK_NULL\n") : print("NG_NULL\n"); 107$r = mb_strpos($euc_jp, $t_ary, 'EUC-JP'); 108($r === FALSE) ? print("OK_ARRAY\n") : print("NG_ARRAY\n"); 109$r = mb_strpos($euc_jp, $t_obj, 'EUC-JP'); 110($r === FALSE) ? print("OK_OBJECT\n") : print("NG_OBJECT\n"); 111$r = mb_strpos($euc_jp, $t_obj, 'BAD_ENCODING'); 112($r === FALSE) ? print("OK_BAD_ENCODING\n") : print("NG_BAD_ENCODING\n"); 113 114 115?> 116 117--EXPECT-- 118== POSITIVE OFFSET == 11910 1200 1213 1220 12334 12430 12533 12630 127== NEGATIVE OFFSET == 128ERR: Warning 129OK_NEGATIVE_OFFSET 130ERR: Warning 131OK_NEGATIVE_OFFSET 132ERR: Warning 133OK_NEGATIVE_OFFSET 134ERR: Warning 135OK_NEGATIVE_OFFSET 136ERR: Warning 137OK_NEGATIVE_OFFSET 138ERR: Warning 139OK_NEGATIVE_OFFSET 140ERR: Warning 141OK_NEGATIVE_OFFSET 142ERR: Warning 143OK_NEGATIVE_OFFSET 144== OUT OF RANGE == 145OK_OUT_RANGE 146OK_OUT_RANGE 147OK_OUT_RANGE 148OK_OUT_RANGE 149== NON-EXISTENT == 150OK_STR 151OK_NEWLINE 152== NO ENCODING PARAMETER == 15310 1540 1553 1560 157OK_STR 158OK_NEWLINE 159== NO OFFSET AND ENCODING PARAMETER == 16010 1610 1623 1630 164OK_STR 165OK_NEWLINE 166== INVALID PARAMETER TEST == 167ERR: Warning 168OK_NULL 169ERR: Warning 170OK_ARRAY 171ERR: Warning 172OK_OBJECT 173ERR: Warning 174OK_BAD_ENCODING 175 176