Backend Development 3 min read

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.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
PHP stripos() Function: Case‑Insensitive Search for a Substring Position

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.

BackendPHPTutorialstring-functionscase-insensitivestripos
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.