One minute
MySQL Strip HTML Tags
To replicate PHP’s strip_tags()
function in MySQL, this is about as close as I could get without writing a custom function. You must have MySQL >= v5.5 for this to work.
Using the REGEXP_REPLACE
function:
UPDATE table_name
SET column_name = REGEXP_REPLACE(column_name, '<[^>]*>', '');
Another option for stripping HTML tags in MySQL is to use the ExtractValue
function. This function can extract values from an XML document stored in a column, and can be used to remove HTML tags as well.
UPDATE table_name
SET column_name = TRIM(REPLACE(ExtractValue(column_name, '//text()'), ' ', ' '));
Note: The REPLACE()
is because I kept finding that MySQL was sometimes leaving 3 spaces where it had stripped HTML.