"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How can I Extract Plain Text from HTML Using MySQL Queries?

How can I Extract Plain Text from HTML Using MySQL Queries?

Published on 2024-11-18
Browse:531

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:

  • [MySQL XML Functions Documentation](https://dev.mysql.com/doc/refman/5.5/en/xml-functions.html)
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3