Загрузка...

str_contains() in PHP 8+

If we want to search a small piece of string in a big string then we can use function str_contains().

Here is str_contains() at a glance.
1. It contains the main string or the string where we are searching as the first parameter. This is called haystack.
2. The string that need to be searched is the second parameter. This is called needle.
3. This function returns boolean value - true if the string found, else false.
4. This function is case-sensitive.
5. If the search string is empty then it returns true.
6. It is introduced since version 8.

Here is an example.
We are searching string "Super" in the heredoc. The result will be true, as it is found.
$heredoc = "Math is Super easy";
$needle = "Super";
$result = str_contains($heredoc, $needle);
echo $result;

Now, we are changing the needle in small letters and search again. The result is false, because small case super is not available in the heredoc and as this function is case-sensitive.
$heredoc = "Math is Super easy";
$needle = "super";
$result = str_contains($heredoc, $needle);
echo $result;

Видео str_contains() in PHP 8+ канала PHP Explained
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять