0

Here i remove all attributes from tags:

$body = preg_replace('/<(\w+) [^>]+>/', '<$1>', $body); //remove attributes from html

How do i amend to exclude style tags?

user892134
  • 3,078
  • 16
  • 62
  • 128

1 Answers1

0

You could add a negative lookahead to the regex pattern which excludes style tags:

$body = preg_replace('/<(?!style\b)(\w+) [^>]+>/', '<$1>', $body);
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360