PHP - Strings - Remove a HTML tag with a specific class, including its contents

Something like this is what you're looking for...

$output = preg_replace("#<h3 class=\"hdr\">(.*?)</h3>#is", "", $input);

Use "is" at the end of the regex because it will cause it to be case insensitive which is more flexible.


Using as little code as possible? Shortest code isn't necessarily best. However, if your HTML h3 tag always looks like that, this should suffice:

$html = preg_replace('#<h3 class="hdr">(.*?)</h3>#', '', $html);

Generally speaking, using regex for parsing HTML isn't a particularly good idea though.