What are some best practices for removing HTML tags between specific tags using PHP?

When removing HTML tags between specific tags using PHP, one approach is to use regular expressions to match the content between the specific tags and then strip out any HTML tags within that content. This can be achieved by using the preg_replace() function in PHP.

// Sample HTML content
$html = "<div>This is <strong>some</strong> text <a href='#'>with</a> HTML tags</div>";

// Remove HTML tags between <div> tags
$cleaned_html = preg_replace('/<div>(.*?)<\/div>/s', function($match) {
    return '<div>' . strip_tags($match[1]) . '</div>';
}, $html);

echo $cleaned_html;