Replace HTML entities with regular expression

Bajrang picture Bajrang · Jan 10, 2012 · Viewed 7.7k times · Source

I would like a regular expression in PHP to find all HTML entities such as "<br /> <br /> ..etc. " in order to remove them from a long string.

Answer

ridgerunner picture ridgerunner · Jan 10, 2012

This one removes alpha, decimal and hex HTML entities:

$text = preg_replace('/&(?:[a-z\d]+|#\d+|#x[a-f\d]+);/i', '', $text);