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.

SELECT TRIM(REPLACE(ExtractValue(columntostrip, '//text()'), '   ', ' '))
FROM table;

Note: The REPLACE() is because I kept finding that MySQL was sometimes leaving 3 spaces where it had stripped HTML.

Related Posts

Import Gzipped Mysql Dump
Html Picture Element Hack
Kill All MySQL Queries With State
© 2014 - 2022 · Home ·