What is the best practice for ignoring HTML tags while searching for a specific string within a text in PHP?

When searching for a specific string within a text that contains HTML tags in PHP, it is best practice to strip the HTML tags before performing the search. This ensures that the search is performed only on the text content and not on any HTML markup.

// Function to strip HTML tags from a string
function strip_tags_content($text) {
    return strip_tags($text);
}

// Text containing HTML tags
$text = "<p>This is a <strong>sample</strong> text.</p>";

// Search term
$searchTerm = "sample";

// Strip HTML tags from the text
$strippedText = strip_tags_content($text);

// Perform search on the stripped text
if (strpos($strippedText, $searchTerm) !== false) {
    echo "Search term found!";
} else {
    echo "Search term not found.";
}