Home >Database >Mysql Tutorial >How can I remove HTML tags from a MySQL database?

How can I remove HTML tags from a MySQL database?

Susan Sarandon
Susan SarandonOriginal
2024-11-15 08:21:021001browse

How can I remove HTML tags from a MySQL database?

MySQL Query to Remove HTML Tags

You have a substantial database filled with records containing HTML tags (). Removing these tags is essential. While PHP provides the strip_tags method, running a PHP script to modify all the records can be time-consuming.

MySQL Solution

MySQL version 5.5 and later offer XML functions that can address this issue:

SELECT ExtractValue(field, '//text()') FROM table;

This query extracts only the text content from the specified "field" column in the "table." It relies on the XML functions provided by MySQL to parse the HTML tags and retrieve the text content.

Reference

For more details on XML functions in MySQL, refer to the official documentation:
https://dev.mysql.com/doc/refman/5.5/en/xml-functions.html

The above is the detailed content of How can I remove HTML tags from a MySQL database?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn