What is the function used in PHP to find the position of a specific word in a string?

To find the position of a specific word in a string in PHP, you can use the strpos() function. This function searches for the first occurrence of a substring within a string and returns the position of the substring if it is found. If the substring is not found, it returns false. To use this function, you need to provide the string to search within and the specific word you are looking for.

$string = "This is a sample string to demonstrate strpos function in PHP";
$word = "sample";

$position = strpos($string, $word);

if ($position !== false) {
    echo "The word '$word' was found at position: $position";
} else {
    echo "The word '$word' was not found in the string";
}