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 查詢從 HTML 中提取純文字?的詳細內容。更多資訊請關注PHP中文網其他相關文章!