How to stop an html TEXTAREA from decoding html entities

后端 未结 6 1260
眼角桃花
眼角桃花 2021-01-01 12:46

I have a strange problem:

In the database, I have a literal ampersand lt semicolon:

<div  

whenever its printed into a html

6条回答
  •  爱一瞬间的悲伤
    2021-01-01 13:00

    You have to be sure that this is rendered to the browser:

    
    

    Essentially, this means that the & in < has to be html encoded to &. How to do it will depend on the technologies you're using.

    UPDATE: Think about it like this. If you want to display

    inside a textarea, you'll have to encode <> because otherwise,
    would be a normal HTML element to the browser:

    
    

    Having said this, if you want to display <div> inside a textarea, you'll have to encode & again, because the browser decodes HTML entities when rendering HTML. It has nothing to do with your database.

提交回复
热议问题