There are times when you want to remove a specific HTML tag from an HTML block of text.

This could be an anchor(<a/>>) or an image(<img/>) perhaps.

You can use preg_replace to do this quite quickly and efficiently.

Remove an anchor:
[code lang=”php”]
$content = “Sample text Our anchor. Etc etc”;
$content = preg_replace(‘/<\/?a[^>]*>/’,”,$content);
//$content is now -> “Sample text. Etc etc”;
[/code]

Remove an image:
[code lang=”php”]
$content = “Sample text . Etc etc”;
$content = preg_replace(‘/<\/?a[^>]*>/’,”,$content);
//$content is now -> “Sample text. Etc etc”;
[/code]