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:
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