Returns all of haystack
starting from and including the first
occurrence of needle
to the end.
haystack
The string to search in
needle
The string to search for.
До версії PHP 8.0.0, якщо параметр needle
не є рядком,
він перетворюється на ціле число і розглядається як код символу. Ця поведінка
є застарілою, починаючи з PHP 7.3.0. Вкрай не рекомендується на неї
покладатися. Залежно від потрібної поведінки, параметр
needle
необхідно привести до рядкового типу або
обробити функцією chr().
before_needle
If true
, stristr()
returns the part of the haystack
before the
first occurrence of the needle
(excluding needle).
needle
and haystack
are examined in a case-insensitive manner.
Returns the matched substring. If needle
is not
found, returns false
.
Версія | Опис |
---|---|
8.2.0 | Приведення до одного регістру не залежить від локалі, що встановлена функцією setlocale(). Перетворюються тільки ASCII-символи. Байти, які не належать до ASCII, порівнюються за своїми значеннями. |
8.0.0 |
Тепер параметр needle може бути порожнім рядком.
|
8.0.0 |
Passing an int as needle is no longer supported.
|
7.3.0 |
Passing an int as needle has been deprecated.
|
Приклад #1 stristr() example
<?php
$email = 'USER@EXAMPLE.com';
echo stristr($email, 'e'); // outputs ER@EXAMPLE.com
echo stristr($email, 'e', true); // outputs US
?>
Приклад #2 Testing if a string is found or not
<?php
$string = 'Hello World!';
if(stristr($string, 'earth') === FALSE) {
echo '"earth" not found in string';
}
// outputs: "earth" not found in string
?>
Приклад #3 Using a non "string" needle
<?php
$string = 'APPLE';
echo stristr($string, 97); // 97 = lowercase a
// outputs: APPLE
?>
Зауваження: Ця функція є бінарно безпечною.