stristr
(PHP 4, PHP 5, PHP 7, PHP 8)
stristr — Case-insensitive strstr()
Параметри
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.
Приклади
Приклад #1 stristr() example
<?php
$email = 'USER@EXAMPLE.com';
echo stristr($email, 'e'), PHP_EOL; // outputs ER@EXAMPLE.com
echo stristr($email, 'e', true), PHP_EOL; // 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
?>
Примітки
Зауваження: Ця функція є бінарно
безпечною.
Прогляньте також
- strstr() - Find the first occurrence of a string
- strrchr() - Find the last occurrence of a character in a string
- stripos() - Find the position of the first occurrence of a case-insensitive substring in a string
- strpbrk() - Search a string for any of a set of characters
- preg_match() - Perform a regular expression match