Home > Database > Mysql Tutorial > body text

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

Linda Hamilton
Release: 2024-11-15 03:12:02
Original
979 people have browsed it

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;
Copy after login

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)

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template