Home >Database >Mysql Tutorial >How can I Extract Plain Text from HTML Using MySQL Queries?
Extracting Plain Text from HTML Using MySQL Queries
To remove HTML tags from database records, you can leverage MySQL XML functions instead of employing a PHP script. Here's how:
Query Using ExtractValue() for MySQL >= 5.5
Starting with MySQL version 5.5, the ExtractValue() function allows you to extract text content from within XML elements. By passing the HTML field to ExtractValue() and specifying the XPath expression '//text()', you can retrieve the plain text value:
SELECT ExtractValue(field, '//text()') FROM table;
This query effectively removes all HTML tags from the specified field, returning only the plain text content.
Reference:
The above is the detailed content of How can I Extract Plain Text from HTML Using MySQL Queries?. For more information, please follow other related articles on the PHP Chinese website!