Created
August 4, 2018 07:54
-
-
Save vanleantking/0b43fc35d63ef06d5522665bd24edce5 to your computer and use it in GitHub Desktop.
Remove inline styles in HTML file by using PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Use preg_replace function to make regex on HTML tag contain style | |
$value = preg_replace('/(<[^>]*) style=("[^"]+"|\'[^\']+\')([^>]*>)/i', '$1$3', $value); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$text = preg_replace('#(<[a-z ])(style=("|')(.?)("|'))([a-z ]*>)#', '\1\6', $text);