int strpos ( string $haystack, string $needle [ , int $offset=0 ] )


strpos() finds the numeric position of the first occurrence of needle in the haystack string

※ available F/W version : all


Return values

Returns the position of where the needle exists relative to the beginning of the haystack string(independent of offset).
The string positions start at 0, and not 1.
Returns FALSE if needle was not found.
Otherwise PHP error


$haystack = "Hello PHPoC World!";
$needle1 = "PHP";
$needle2 = "H";

$pos = strpos($haystack, $needle1);
echo "needle1: $needle1 at position $pos\r\n";  // OUTPUT: needle1: PHP at position 6
$pos = strpos($haystack, $needle2, 2);
echo "needle2: $needle2 at position $pos\r\n";  // OUTPUT: needle2: H at position 7

See also

str_repeat() / substr() / str_replace() / substr_replace()


This function is identical to the PHP group’s strpos() function.