SyntaxStudy
Sign Up
Home PHP Reference strpos()

strpos()

function

Finds position of first occurrence of a substring. Returns false if not found — always use strict comparison (!==).

Syntax

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

Example

php
<?php
$str = 'Hello World Hello';
echo strpos($str, 'Hello');    // 0
echo strpos($str, 'World');    // 6
echo strrpos($str, 'Hello');  // 12

if (strpos($str, 'World') !== false) {
    echo 'Found!';
}
echo stripos('Hello World', 'hello'); // 0