PHP strripos() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
String

Definition

In PHP, strripos() finds the position of the last occurrence of a substring in a string, ignoring case.

It is the case-insensitive version of strrpos(). Counting starts at 0, and it returns false when there is no match.

Syntax

Call strripos() with the values you need. Start with this line.

PHP
$pos = strripos("Hello hello", "HELLO");
CallWhat it does
strripos("Hello hello", "HELLO")Returns 6.
strripos("php is fun, I love PHP", "php")Returns 19.
strripos("abc", "x")Returns false because there is no match.

A negative offset starts the search that many characters from the end of the string. Use strpos() or stripos() to find the first occurrence instead.

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

Parameters

ParameterDescription
haystackRequired. The string to search in.
needleRequired. The text to find. Case is ignored.
offsetOptional. Where to start (positive) or stop (negative) the search.

Return Value

Return ValueDescription
intThe zero-based position of the last match.
falseReturned when the needle is not found.

PHP Examples

Example 1 — Find the Last Match Ignoring Case

Search for the last "hello" in any capitalization.

PHP
<?php
$text = "Hello hello";
$pos = strripos($text, "HELLO");

echo $pos, PHP_EOL;

How It Works

  1. The string contains "Hello" at 0 and "hello" at 6.
  2. Search for "HELLO" in uppercase.
  3. Case is ignored, so both match.
  4. strripos returns the position of the last one: 6.

Example 2 — No Match Returns false

When the needle does not exist, you get false.

PHP
<?php
$result = strripos("abc", "x");

var_dump($result);

How It Works

  1. Search "abc" for the letter "x".
  2. It does not exist in any case.
  3. strripos returns false.
  4. Use !== false when you test for a match.

Example 3 — First vs Last Position

Compare stripos() with strripos() on the same text.

PHP
<?php
$text = "php is fun, I love PHP";

echo stripos($text, "php"), PHP_EOL;
echo strripos($text, "php"), PHP_EOL;

How It Works

  1. The text has "php" at the start and "PHP" at the end.
  2. stripos finds the first match at index 0.
  3. strripos searches from the end and finds the last match.
  4. That match starts at index 19.

Frequently Asked Questions

strripos() returns the index of the last occurrence of a substring, ignoring case. It returns false if nothing matches.
strrpos() is case-sensitive, while strripos() ignores case. Both search for the last occurrence.
A negative offset makes the search start that many characters from the end and look backwards, so it ignores the end of the string.
It returns false. Compare with === false rather than using a loose if.
Use stripos(). It works from the start of the string and returns the first position.

Next: strrpos()

strrpos() finds the position of the last occurrence of a substring in a string.

strrpos() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful