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 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_strpos($euc_jp, '���ܸ�', 0, 'EUC-JP') . "\n"; 25print mb_strpos($euc_jp, '0', 0, 'EUC-JP') . "\n"; 26print mb_strpos($euc_jp, 3, 0, 'EUC-JP') . "\n"; 27print mb_strpos($euc_jp, 0, 0, 'EUC-JP') . "\n"; 28print mb_strpos($euc_jp, '���ܸ�', 15, 'EUC-JP') . "\n"; 29print mb_strpos($euc_jp, '0', 15, 'EUC-JP') . "\n"; 30print mb_strpos($euc_jp, 3, 15, 'EUC-JP') . "\n"; 31print mb_strpos($euc_jp, 0, 15, 'EUC-JP') . "\n"; 32 33 34// Negative offset 35echo "== NEGATIVE OFFSET ==\n"; 36 37print mb_strpos($euc_jp, '���ܸ�', -15, 'EUC-JP') . "\n"; 38print mb_strpos($euc_jp, '0', -15, 'EUC-JP') . "\n"; 39print mb_strpos($euc_jp, 3, -15, 'EUC-JP') . "\n"; 40print mb_strpos($euc_jp, 0, -15, 'EUC-JP') . "\n"; 41print mb_strpos($euc_jp, 0, -43, 'EUC-JP') . "\n"; 42 43 44// Non-existent 45echo "== NON-EXISTENT ==\n"; 46 47$r = mb_strpos($euc_jp, '�ڹ��', 0, 'EUC-JP'); 48($r === FALSE) ? print "OK_STR\n" : print "NG_STR\n"; 49$r = mb_strpos($euc_jp, "\n", 0, 'EUC-JP'); 50($r === FALSE) ? print "OK_NEWLINE\n" : print "NG_NEWLINE\n"; 51 52 53// EUC-JP - No encoding parameter 54echo "== NO ENCODING PARAMETER ==\n"; 55 56mb_internal_encoding('EUC-JP') or print("mb_internal_encoding() failed\n"); 57 58print mb_strpos($euc_jp, '���ܸ�', 0) . "\n"; 59print mb_strpos($euc_jp, '0', 0) . "\n"; 60print mb_strpos($euc_jp, 3, 0) . "\n"; 61print mb_strpos($euc_jp, 0, 0) . "\n"; 62 63$r = mb_strpos($euc_jp, '�ڹ��', 0); 64($r === FALSE) ? print "OK_STR\n" : print "NG_STR\n"; 65$r = mb_strpos($euc_jp, "\n", 0); 66($r === FALSE) ? print "OK_NEWLINE\n" : print "NG_NEWLINE\n"; 67 68// EUC-JP - No offset and encoding parameter 69echo "== NO OFFSET AND ENCODING PARAMETER ==\n"; 70 71mb_internal_encoding('EUC-JP') or print("mb_internal_encoding() failed\n"); 72 73print mb_strpos($euc_jp, '���ܸ�') . "\n"; 74print mb_strpos($euc_jp, '0') . "\n"; 75print mb_strpos($euc_jp, 3) . "\n"; 76print mb_strpos($euc_jp, 0) . "\n"; 77 78$r = mb_strpos($euc_jp, '�ڹ��'); 79($r === FALSE) ? print "OK_STR\n" : print "NG_STR\n"; 80$r = mb_strpos($euc_jp, "\n"); 81($r === FALSE) ? print "OK_NEWLINE\n" : print "NG_NEWLINE\n"; 82 83?> 84--EXPECT-- 85String len: 43 86== POSITIVE OFFSET == 8710 880 893 900 9134 9230 9333 9430 95== NEGATIVE OFFSET == 9634 9730 9833 9930 1000 101== NON-EXISTENT == 102OK_STR 103OK_NEWLINE 104== NO ENCODING PARAMETER == 10510 1060 1073 1080 109OK_STR 110OK_NEWLINE 111== NO OFFSET AND ENCODING PARAMETER == 11210 1130 1143 1150 116OK_STR 117OK_NEWLINE 118