Description Edit

strpos will return the numeric position of a search string inside the given string. Note that the position in string starts with 0 and not with 1. If the optional offset parameter was set it starts searching at the character with that number. The return value will still be relative to the beginning of the string.

Note: strpos may return boolean false, but may also return a non-boolean value which evaluates to false, like 0 or an empty string (""). Use the === operator for testing the return value of this function.

Parameters Edit

{{{returns}}} strpos (string input, string search [, integer offset])

Parameter Infos Edit

Parameter PHP Version Type
strpos 4 or 5 returns integer
input 4 or 5 string
search 4 or 5 integer

Examples Edit

Example 1: The direct way Edit

 echo strpos("Find a string", "string");

Output Edit


Example 2: Using a variable and offset Edit

 $string = "abcdef abcdef";
 $find   = "a";
 echo strpos($string, $find, 1); // Stars searching at the first b

Output Edit


See also Edit

strrpos, stripos, strripos, strrchr, substr, stristr, strstr

For more details on this function, visit its entry in the php manual.