array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'uk', ), 'this' => array ( 0 => 'function.strripos.php', 1 => 'strripos', 2 => 'Find the position of the last occurrence of a case-insensitive substring in a string', ), 'up' => array ( 0 => 'ref.strings.php', 1 => 'String Функції', ), 'prev' => array ( 0 => 'function.strrev.php', 1 => 'strrev', ), 'next' => array ( 0 => 'function.strrpos.php', 1 => 'strrpos', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/strings/functions/strripos.xml', ), 'history' => array ( ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); contributors($setup); ?>

strripos

(PHP 5, PHP 7, PHP 8)

strriposFind the position of the last occurrence of a case-insensitive substring in a string

Опис

strripos(string $haystack, string $needle, int $offset = 0): int|false

Find the numeric position of the last occurrence of needle in the haystack string.

Unlike the strrpos(), strripos() is case-insensitive.

Параметри

haystack

The string to search in.

needle

The string to search for.

До версії PHP 8.0.0, якщо параметр needle не є рядком, він перетворюється на ціле число і розглядається як код символу. Ця поведінка є застарілою, починаючи з PHP 7.3.0. Вкрай не рекомендується на неї покладатися. Залежно від потрібної поведінки, параметр needle необхідно привести до рядкового типу або обробити функцією chr().

offset

If zero or positive, the search is performed left to right skipping the first offset bytes of the haystack.

If negative, the search is performed right to left skipping the last offset bytes of the haystack and searching for the first occurrence of needle.

Зауваження:

This is effectively looking for the last occurrence of needle before the last offset bytes.

Значення, що повертаються

Returns the position where the needle exists relative to the beginnning of the haystack string (independent of search direction or offset).

Зауваження: String positions start at 0, and not 1.

Returns false if the needle was not found.

Увага

Ця функція може повертати як логічне false, так і не логічне значення, яке прирівнюється до 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 A simple strripos() example

<?php
$haystack
= 'ababcd';
$needle = 'aB';

$pos = strripos($haystack, $needle);

if (
$pos === false) {
echo
"Sorry, we did not find ($needle) in ($haystack)";
} else {
echo
"Congratulations!\n";
echo
"We found the last ($needle) in ($haystack) at position ($pos)";
}
?>

Поданий вище приклад виведе:

Congratulations!
   We found the last (aB) in (ababcd) at position (2)

Прогляньте також