1
0
mirror of https://github.com/php/php-src.git synced 2026-04-27 18:23:26 +02:00
Files
archived-php-src/ext/mbstring/tests/mb_strpos_empty_needle.phpt
Jorg Adam Sowa 1e02099e6a ext/mbstring: Use internal_encoding INI setting instead of mb_internal_encoding() in tests (#19663)
Moves the usage of `mb_internal_encoding()` to INI section for the tests not testing the encoding/function itself, but the other mbstring/iconv functions.
2025-09-03 11:34:12 +01:00

91 lines
2.4 KiB
PHP

--TEST--
Test mb_strpos() function : with empty needle
--EXTENSIONS--
mbstring
--INI--
internal_encoding=UTF-8
--FILE--
<?php
$string_ascii = 'abc def';
// Japanese string in UTF-8
$string_mb = "日本語テキストです。0123456789。";
echo "\n-- ASCII string without offset --\n";
var_dump(mb_strpos($string_ascii, ''));
echo "\n-- ASCII string with in range positive offset --\n";
var_dump(mb_strpos($string_ascii, '', 2));
echo "\n-- ASCII string with in range negative offset --\n";
var_dump(mb_strpos($string_ascii, '', -2));
echo "\n-- ASCII string with out of bound positive offset --\n";
try {
var_dump(mb_strpos($string_ascii, '', 15));
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}
echo "\n-- ASCII string with out of bound negative offset --\n";
try {
var_dump(mb_strpos($string_ascii, '', -15));
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}
echo "\n-- Multi-byte string without offset --\n";
var_dump(mb_strpos($string_mb, ''));
echo "\n-- Multi-byte string with in range positive offset --\n";
var_dump(mb_strpos($string_mb, '', 2));
echo "\n-- Multi-byte string with in range negative offset --\n";
var_dump(mb_strpos($string_mb, '', -2));
echo "\n-- Multi-byte string with out of bound positive offset --\n";
try {
var_dump(mb_strpos($string_mb, '', 150));
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}
echo "\n-- Multi-byte string with out of bound negative offset --\n";
try {
var_dump(mb_strpos($string_mb, '', -150));
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}
?>
--EXPECT--
-- ASCII string without offset --
int(0)
-- ASCII string with in range positive offset --
int(2)
-- ASCII string with in range negative offset --
int(5)
-- ASCII string with out of bound positive offset --
mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
-- ASCII string with out of bound negative offset --
mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
-- Multi-byte string without offset --
int(0)
-- Multi-byte string with in range positive offset --
int(2)
-- Multi-byte string with in range negative offset --
int(19)
-- Multi-byte string with out of bound positive offset --
mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
-- Multi-byte string with out of bound negative offset --
mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)