What are some best practices for handling cases where the search term is not found using strpos in PHP?

When using strpos in PHP to search for a specific term within a string, it is important to handle cases where the term is not found to prevent errors or unexpected behavior. One common practice is to check the return value of strpos, which will be false if the term is not found. By using strict comparison (===) to check for false, we can accurately determine if the search term is not present in the string.

$string = "Hello, World!";
$searchTerm = "foo";

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

if ($position === false) {
    echo "Search term not found in string.";
} else {
    echo "Search term found at position: " . $position;
}