PHP stripos() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
String

Definition

In PHP, stripos() finds the position of the first match of a substring, ignoring letter case.

It returns the zero-based position, or false if there is no match.

Syntax

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

PHP
$pos = stripos($text, "world");
CallWhat it does
stripos("Hello World", "WORLD")Returns 6.
stripos("abcABC", "b", 2)Returns 4 (search starts at index 2).

Positions start at 0. This is the case-insensitive version of strpos().

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

Parameters

ParameterDescription
haystackRequired. The string to search in.
needleRequired. The text to find.
offsetOptional. Where to start searching. A negative value counts from the end. Default is 0.

Return Value

Return ValueDescription
intThe position of the first match, starting at 0.
falseReturned when the needle is not found.

PHP Examples

Example 1 — Find a Word Ignoring Case

Upper and lower case are treated the same.

PHP
<?php
$pos = stripos("Hello World", "WORLD");

echo $pos, PHP_EOL;

How It Works

  1. Pass a haystack. It is "Hello World".
  2. Search in capitals. WORLD still matches.
  3. Count from 0. The word starts at index 6.
  4. Print the position. The output is 6.

Example 2 — Position 0 vs Not Found

Position 0 is a real match. Use strict comparison.

PHP
<?php
$pos = stripos("PHP rocks", "php");
echo $pos === false ? "not found" : "found at " . $pos, PHP_EOL;

$none = stripos("PHP rocks", "java");
echo $none === false ? "not found" : "found at " . $none, PHP_EOL;

How It Works

  1. Match at the start. The position is 0.
  2. Use === false. Zero is not treated as a failure.
  3. Search for a missing word. java is not in the text.
  4. Get false. The second line prints not found.

Example 3 — Find the Second Match

Use the offset to continue after the first match.

PHP
<?php
$text = "The cat and the hat";

$first = stripos($text, "the");
$second = stripos($text, "the", $first + 1);

echo $first, PHP_EOL;
echo $second, PHP_EOL;

How It Works

  1. Find the first match. The is at index 0.
  2. Move the offset. Start searching one step later.
  3. Find the second match. Lowercase the is at index 12.
  4. Print both. The case did not matter.

Frequently Asked Questions

stripos() returns the position of the first occurrence of a substring in a string, ignoring upper and lower case.
stripos(string $haystack, string $needle, int $offset = 0): int|false. The offset is optional.
strpos() is case-sensitive. stripos() ignores case, so "PHP" matches "php".
A match at the very start returns 0. A loose check like if (!$pos) would wrongly treat it as not found.
In PHP 8, use str_contains() for a yes/no answer. For a case-insensitive check, lowercase both strings first.

Next: stripslashes()

stripslashes() removes backslashes added to a string, such as by addslashes().

stripslashes() 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