Stripping HTML tags in PostgreSQL

后端 未结 5 1312
臣服心动
臣服心动 2020-12-06 02:30

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 be

5条回答
  •  庸人自扰
    2020-12-06 03:29

    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.

    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.

提交回复
热议问题