stripos
Finds the position of a substring, ignoring case.
Syntax
stripos(string $haystack, string $needle, int $offset = 0): int|falseParameters
| Parameter | Type | Description |
|---|---|---|
| $haystack | string | The string to search in. |
| $needle | string | What to look for. |
| $offset | int | Optional. 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.