php - htmlentities 正在破坏超链接

标签 php mysql html-entities

我正在尝试做一些 htmlentities。但是,由于超链接被转换为 html 代码,现在超链接被破坏了,出于一些愚蠢的原因,大学为我们提供了相同的服务器密码。

去年我几乎失败了,因为有人进入我的服务器并充满了 javascript 和 css 黑客,所以这将阻止它,但是如果超链接不起作用,它就没有多大用处,那么我该如何防止呢?这是我目前针对该特定区域的代码:

$sub = substr($row['content'],0,300).'.......... <a href="blogpost.php?id='.$row['id'].'">See full article</a>';
echo htmlentities($sub,ENT_QUOTES,"UTF-8");

如果有人能提供帮助,我们将不胜感激,谢谢。

最佳答案

我认为您对太多输出应用了 htmlentities()。就这样做吧:

<?php echo htmlentities(substr($row['content'],0,300)).
           '&hellip;<a href="blogpost.php?id="'.htmlentities($row['id']).'">See full article</a>'; ?>

关于php - htmlentities 正在破坏超链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20622101/

相关文章:

php - 在外部存储过程中使用 MySQL 变量

php - 检查字符串中的坏词?

PHP-SQL : fetching results in round robin fashion

PHP html实体

php - 如何获取文本框的分割值

php - 是否可以将两个 JSON 对象从 PHP 发送到 Swift?

javascript - 存在文本时 JSON.parse 错误\' or\"

mysql - 子查询返回超过 1 行,找不到任何答案

javascript - 如何获得原始实体的 attr?

android - "hamburger icon"或 HTML 实体 ☰ 的回退是什么?