PHP » Strings » strpos()

Syntax:
int strpos(string s, string search [, int offset])
s
String to search in.
search
Character sequence to search for.

Returns the position of a substring.

strpos() returns the position of the first occurrence of a string within another string. An offset can optionally be used to set a position where the search should start. If no occurrence is found, FALSE is returned.

Examples

Code:
<?php

print 'Position of "world": ' . strpos("Hello world", "world") . "<br>";
if (!strpos("Hello world", "Hello", 5))
   print '"Hello" not found after position 5';

?>
Output:
Position of "world": 6
"Hello" not found after position 5
Explanation:

This code shows how strpos() can be used both with and without the offset parameter.

See Also: