PHP stripos() Function: Case‑Insensitive Search for a Substring Position
This article explains the PHP stripos() function, which performs a case‑insensitive search for the first occurrence of a needle string within a haystack string, describes its parameters and return values, and provides a complete example with code illustrating typical usage and edge‑case handling.
The stripos() function in PHP finds the position of the first occurrence of a needle string inside a haystack string without regard to case.
Syntax:
int stripos(string $haystack, string $needle [, int $offset = 0])
Description: It returns the numeric position where $needle first appears in $haystack . The search can start at an optional $offset , but the returned position is always relative to the beginning of $haystack .
Parameters:
haystack : The string to be searched.
needle : The string (or single character) to look for; non‑string values are cast to integers.
offset (optional): The character position in $haystack where the search should begin.
Return value: The function returns the position of $needle in $haystack (starting at 0). If the needle is not found, it returns FALSE .
Example:
The example demonstrates that a strict identity check ( === ) is required to distinguish a valid position of 0 from FALSE , and shows how stripos() behaves with different case variations.
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.