You are currently viewing PHP strpos() Function with Example
  • Post category:PHP

PHP strpos() Function with Example

strpos in PHP Example

In this article, we will discuss strpos function in php with an example code. This strpos() function is PHP in-built function and it is used to find the occurrence of a substring within the given string. We should pass three arguments strpos(string, find, start). Start argument is optional. The strpos() function is used to search for a string or character within a string. If a match is found in the string, this function will return the position of the first match. If no match is found, it will return FALSE.


$str= "There is a cat in the tree, and I think it is my cat! ";
echo strpos($str, "tree");


Here, the output is 22, which means the string “tree” character starting position is 22.

Leave a Reply