What's the best practice to set html attribute via PHP?

后端 未结 4 956
遥遥无期
遥遥无期 2020-11-27 06:07

When doing this job in PHP,one may meet this kind of issue:

\">...

The problem is that if

4条回答
  •  我在风中等你
    2020-11-27 06:39

    You always want to HTML-encode things inside HTML attributes, which you can do with htmlspecialchars:

    
    

    You probably want to set the second parameter ($quote_style) to ENT_QUOTES.

    The only potential risk is that $variable may already be encoded, so you may want to set the last parameter ($double_encode) to false.

提交回复
热议问题