strpos()
Published Jul 20, 2023Updated Jul 20, 2023
Contribute to Docs
The strpos()
function performs a case-sensitive search for the position of the first occurrence of a substring in a given string. If the substring is found, it will return the index of the beginning of the substring. If it isn’t found, the function won’t return any output.
Syntax
strpos(string, find, start)
Parameters:
string
is the string that the function searches.find
is the value to search for withinstring
.start
tells the function to start the search at a specified index which is optional.
Note: If the substring is found, the function returns the position where the substring starts. If the substring is not found, it returns
false
.
Example
The following code demonstrates a basic implementation of strpos()
:
<?phpecho strpos("I love PHP, I love php too!","php");?>
The output of the above code will be:
19
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.