PHP 8 reference · String Functions

PHP stripos() Function

Find the position of the first occurrence of a substring, ignoring case. Returns false when there's no match.

PHP 8 Since 5.0

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

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

Parameters

ParameterDescription
haystack The string to search in.
needle The string to find, in any case.
offset optional Where to start searching. Default: 0

Return value

The position, or false.

Examples

Case-insensitive searchTry it yourself
<?php
echo stripos("Learn PHP today", "php"), "\n";
var_dump(stripos("Learn PHP today", "python"));

Output

6
bool(false)
Detect a wordTry it yourself
<?php
$agent = "Mozilla/5.0 (iPhone; CPU iPhone OS 17_0)";
echo stripos($agent, "iphone") !== false ? "mobile" : "desktop", "\n";

Output

mobile

Version history

VersionChange
PHP 5.0Added

Was this page helpful?