How to remove html special chars? [duplicate]

Either decode them using html_entity_decode or remove them using preg_replace:

$Content = preg_replace("/&#?[a-z0-9]+;/i","",$Content); 

(From here)

EDIT: Alternative according to Jacco’s comment

might be nice to replace the ‘+’ with
{2,8} or something. This will limit
the chance of replacing entire
sentences when an unencoded ‘&’ is
present.

$Content = preg_replace("/&#?[a-z0-9]{2,8};/i","",$Content); 

Leave a Comment