Find the first occurrence of "php" in a string:
<?php echo strpos ( " I love php, I love php too! " , " php " ) ; ?>The strpos() f function finds the first occurrence of a string in another string (case sensitive).
Note: The strpos() function is case-sensitive.
Note: This function is binary safe.
Related functions:
strrpos() - Finds the last occurrence of a string within another string (case sensitive)
stripos() - Finds the first occurrence of a string within another string (case insensitive)
strripos() - Finds the last occurrence of a string within another string (case insensitive)
strpos( string,find,start )
parameter | describe |
---|---|
string | Required. Specifies the string to be searched for. |
find | Required. Specifies the characters to search for. |
start | Optional. Specifies the location to start the search. |
Return value: | Returns the position of the first occurrence of a string in another string, or FALSE if the string is not found. Note: The string position starts from 0, not from 1. |
---|---|
PHP version: | 4+ |