How do I ensure attribute values containing quotes do not break formatting?

后端 未结 1 920
既然无缘
既然无缘 2021-01-27 13:38

In my database I am storing the title of posts and when I create the links on the page I put the title of the post as the title attribute.



        
1条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-27 14:26

    Use htmlspecialchars to output your strings

    htmlspecialchars("I don't",ENT_QUOTES); // returns I don't
    

    That will also take care of other HTML characters such as < & > as explained in the manual,

    http://php.net/manual/en/function.htmlentities.php

    0 讨论(0)
提交回复
热议问题