Home >>PHP String Functions >PHP strpos() Function
PHP strpos() function is used to find the position of the first occurrence of a given input string in another string.It return an integer value of the position of the first occurrence of the input string. It is case-sensitive. The case-insensitive version of this function is stripos() function.
Syntax:
strpos($string, $search, $start);
Parameter | Description |
---|---|
string | This is a required parameter. This parameter defines the string to search. |
search | This is a required parameter. This parameter defines the string to search for. |
start | start This is an optional parameter. This parameyter defines where to begin the search. |
Here is an example of strpos() function in PHP:
<html> <body> <?php echo stripos("Welcome to PHPTPOINT","PHP"); // case sensitive ?> </body> </html>
Here is an example of strpos() function in PHP:
<html> <body> <?php $str = "Hello Everyone.. Welcome to PHPTPOINT"; echo stripos($str,"Welcome",0); echo "<br>"; echo stripos($str,"Welcome",15); echo "<br>"; echo stripos($str,"Welcome",20); // not found because start position is 20. ?> </body> </html>