Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

stripos

Finds the position of a substring, ignoring case.

Syntax

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

Parameters

ParameterTypeDescription
$haystackstringThe string to search in.
$needlestringWhat to look for.
$offsetintOptional. Where to start.

Return value

int|falseThe position of the first occurrence, or `false`.

Examples

A case-insensitive search:

<?php
 
var_dump(stripos('Hello World', 'WORLD'));
var_dump(stripos('Hello World', 'php'));

Output:

int(6)
bool(false)

Notes

Compare the result with false using !==: position 0 is falsy too. For non-ASCII letters use mb_stripos().

See also

  • strpos — Finds the position of the first occurrence of a substring.
  • str_contains — Checks whether a string contains a given substring.
  • str_ireplace — Replaces a substring ignoring case.

In the tutorial

  • Strings — Working with strings in PHP — quotes, concatenation, length, searching, replacing and multibyte functions.

Thanks for reading!

Donate to the site — we work hard for you.