You could use regular expressions:
$text = preg_relace('#<(.+?)style=(:?"|\')?[^"\']+(:?"|\')?(.*?)>#si', '<a\\1 \\2>', $text);
Crozin
2010-03-21 22:22:49
You could use regular expressions:
$text = preg_relace('#<(.+?)style=(:?"|\')?[^"\']+(:?"|\')?(.*?)>#si', '<a\\1 \\2>', $text);
Couldn't you just use strip_tags and leave in the tags you want eg <p>, <strong>
etc?
I quickly put this together, but for 'inline styles' (!) you will need something like
$text = preg_replace('#(<[a-z ]*)(style=("|\')(.*?)("|\'))([a-z ]*>)#', '\\1\\6', $text);
Why don't you just overwrite the tags. So you will have clean tags without inline styling.
I found this class very useful for doing strip attributes (especially where there's crazy MS Word formatting all through the text):
http://semlabs.co.uk/journal/php-strip-attributes-class-for-xml-and-html