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
Syntax
stripos(string $haystack, string $needle, int $offset = 0): int|false
Parameters
| Parameter | Description |
|---|---|
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
<?php
echo stripos("Learn PHP today", "php"), "\n";
var_dump(stripos("Learn PHP today", "python"));
Output
6 bool(false)
<?php
$agent = "Mozilla/5.0 (iPhone; CPU iPhone OS 17_0)";
echo stripos($agent, "iphone") !== false ? "mobile" : "desktop", "\n";
Output
mobile
Version history
| Version | Change |
|---|---|
| PHP 5.0 | Added |
Related
strpos()· Find the position of the first occurrence of a substring. Returns false if it's not found, so compare with === false.str_contains()· Check whether a string contains a substring and return true or false. Case-sensitive; added in PHP 8.0.- PHP Strings · tutorial