htmlentities正在破坏超链接


htmlentities are breaking hyperlinks

我正在尝试做一些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>'; ?>

不要在整个链接上应用htmlentities,而是在您实际想要转义的值上,比如这个

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