Home

strpos

strpos is a string-searching function in PHP. It returns the position of the first occurrence of a substring (the needle) within another string (the haystack). The search can start at an optional offset, and the return value is the index at which the needle occurs, or false if the needle is not found. The index is 0-based.

If the needle is an empty string, strpos returns 0. When using the result in conditional logic,

There are related functions: stripos performs a case-insensitive search; strrpos returns the last occurrence; mb_strpos is

Notes: strpos is designed for simple substring searching and is not a regular expression engine; for patterns

it
is
important
to
compare
strictly
to
false,
because
a
valid
match
at
position
0
evaluates
to
false
in
a
loose
comparison.
available
for
multibyte
encodings.
The
third
parameter
defines
the
offset
from
which
to
start
the
search;
a
negative
offset
is
counted
from
the
end
of
the
haystack;
if
the
offset
points
beyond
the
string,
the
function
returns
false.
use
preg_match.
It
is
binary-safe,
meaning
it
can
search
in
binary
data
and
does
not
assume
character
encoding.