Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vanleantking/0b43fc35d63ef06d5522665bd24edce5 to your computer and use it in GitHub Desktop.
Save vanleantking/0b43fc35d63ef06d5522665bd24edce5 to your computer and use it in GitHub Desktop.
Remove inline styles in HTML file by using PHP
Use preg_replace function to make regex on HTML tag contain style
$value = preg_replace('/(<[^>]*) style=("[^"]+"|\'[^\']+\')([^>]*>)/i', '$1$3', $value);
@vanleantking
Copy link
Author

$text = preg_replace('#(<[a-z ])(style=("|')(.?)("|'))([a-z ]*>)#', '\1\6', $text);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment