xref: /PHP-8.4/ext/mbstring/tests/mb_strstr.phpt (revision ec348a12)
1--TEST--
2mb_strstr()
3--EXTENSIONS--
4mbstring
5--FILE--
6<?php
7function EUC_JP($utf8str) {
8    return mb_convert_encoding($utf8str, "EUC-JP", "UTF-8");
9}
10
11function FROM_EUC_JP($eucjpstr) {
12    return mb_convert_encoding($eucjpstr, "UTF-8", "EUC-JP");
13}
14
15var_dump(mb_strstr("あいうえおかきくけこ", "おかき"));
16var_dump(mb_strstr("あいうえおかきくけこ", "おかき", false));
17var_dump(mb_strstr("あいうえおかきくけこ", "おかき", true));
18var_dump(FROM_EUC_JP(mb_strstr(EUC_JP("あいうえおかきくけこ"), EUC_JP("おかき"), false, "EUC-JP")));
19var_dump(FROM_EUC_JP(mb_strstr(EUC_JP("あいうえおかきくけこ"), EUC_JP("おかき"), true, "EUC-JP")));
20mb_internal_encoding("EUC-JP");
21var_dump(FROM_EUC_JP(mb_strstr(EUC_JP("あいうえおかきくけこ"), EUC_JP("おかき"))));
22var_dump(FROM_EUC_JP(mb_strstr(EUC_JP("あいうえおかきくけこ"), EUC_JP("おかき"), false)));
23var_dump(FROM_EUC_JP(mb_strstr(EUC_JP("あいうえおかきくけこ"), EUC_JP("おかき"), true)));
24
25// Regression test from when mb_strstr was being reimplemented
26var_dump(bin2hex(mb_strstr("\xdd\x00", "", false, 'UTF-8')));
27var_dump(bin2hex(mb_strstr("M\xff\xff\xff\x00", "\x00", false, "SJIS")));
28
29// Test handling of invalid UTF-8 string
30// Thanks to Stefan Schiller
31var_dump(mb_strstr("\xf0start", "start", false, "UTF-8"));
32var_dump(mb_strstr("\xf0start", "start", true, "UTF-8"));
33
34?>
35--EXPECT--
36string(18) "おかきくけこ"
37string(18) "おかきくけこ"
38string(12) "あいうえ"
39string(18) "おかきくけこ"
40string(12) "あいうえ"
41string(18) "おかきくけこ"
42string(18) "おかきくけこ"
43string(12) "あいうえ"
44string(4) "3f00"
45string(2) "00"
46string(5) "start"
47string(1) "?"
48