在PostgreSQL中剥离HTML标签 [英] Stripping HTML tags in PostgreSQL

查看:306
本文介绍了在PostgreSQL中剥离HTML标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您如何在PostgreSQL中剥离HTML标记,以便保留标记内的数据?

How would you strip HTML tags in PostgreSQL such that the data inside the tags is preserved?

我通过谷歌搜索找到了一些解决方案,但是它们在两者之间剥离文本

I found some solutions by googling it but they were striping the text between the tags too!

推荐答案

在RDBMS中执行的任何解决方案都将涉及字符串处理或正则表达式:据我所知没有任何方法可以在数据库中以符合标准的安全方式来操作HTML。重申一下,您要的是非常非常不安全的。

Any solution performed in the RDBMS is going to involve either string handling or regexes: to my knowledge there is NO way to manipulate HTML in a standards-compliant, safe way in the database. To reiterate, what you are asking for is very, VERY unsafe.

一个更好的选择是在您的应用程序中执行此操作。这是应用程序逻辑,而不是存储层的工作或关注点。

A much better option is to do this in your application. This is application logic, and NOT the job or concern of your storage layer.

一个很好的方法(至少在PHP中)是 HTML净化器。 不要在JavaScript中执行此操作,用户可以很容易地对其进行篡改。

A great way to do this (in PHP, at least) would be HTML purifier. Don't do this in JavaScript, the user can tamper with it very easily.

这篇关于在PostgreSQL中剥离HTML标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆