Google News
logo
PHP Program to Search for a specific text within a string - strpos()
The `strpos()` function in PHP is used to search for the position of the first occurrence of a specific text within a string. It takes two string arguments: the first is the string to be searched, and the second is the text to be found.

Here's an example :
Program :
<?php
$string = "The quick brown fox jumps over the lazy dog.";
$position = strpos($string, "fox");
echo $position;
?>
Output :
16
In this example, we define a string variable `$string` with the value "The quick brown fox jumps over the lazy dog.".

We then use the `strpos()` function to search for the position of the word "fox" within the string, and store the result in a new variable `$position`.

Finally, we use `echo` to output the position of the first occurrence of "fox", which is 16 (counting from 0). Note that if the text is not found in the string, `strpos()` returns `false`.