How to remove htmlentities() values from the database?

前端 未结 6 1600
星月不相逢
星月不相逢 2021-02-08 04:42

Long before I knew anything - not that I know much even now - I desgined a web app in php which inserted data in my mysql database after running the values through htmlent

6条回答
  •  青春惊慌失措
    2021-02-08 05:06

    I had the exact same problem. Since I had multiple clients running the application in production, I wanted to avoid running a PHP script to clean the database for every one of them.

    I came up with a solution that is far from perfect, but does the job painlessly.

    1. Track all the spots in your code where you use htmlentities() before inserting data, and remove that.
    2. Change your "display data as HTML" method to something like this :

      return html_entity_decode(htmlentities($chaine, ENT_NOQUOTES), ENT_NOQUOTES);

    The undo-redo process is kind of ridiculous, but it does the job. And your database will slowly clean itself everytime users update the incorrect data.

提交回复
热议问题