在我的数据库中,我存储了帖子的标题,当我在页面上创建链接时,我将帖子的标题作为title属性。
<a title='here is the description'>bluah</a>
但在页面上发生的事情是,在我的描述中,有一些字符正在破坏它。一个帖子标题的例子
<a title='I don't hanging out with friends, had a great time seeing Sarah again ;p '>bluah</a>
我想我需要做一些HTML编码,但我不确定我应该在什么时候/在哪里做。
谢谢
发布于 2012-11-29 02:55:32
使用htmlspecialchars
输出字符串
htmlspecialchars("I don't",ENT_QUOTES); // returns I don't
这也将照顾到其他HTML字符,如手册中所解释的,
http://php.net/manual/en/function.htmlentities.php
https://stackoverflow.com/questions/13612284
复制相似问题