How can one handle cases where a specific string pattern is not found in a text when using PHP?

If a specific string pattern is not found in a text when using PHP, you can use the `strpos()` function to check if the pattern exists in the text. If `strpos()` returns `false`, it means the pattern is not found. You can then handle this case by displaying an error message or performing a specific action.

$text = "This is a sample text";
$pattern = "pattern";

if(strpos($text, $pattern) === false){
    echo "Pattern not found in the text";
    // Handle the case where the pattern is not found
} else {
    echo "Pattern found in the text";
    // Handle the case where the pattern is found
}