我从数据库中得到一个字符串,我想用函数htmlentities
或输出该字符串htmlspecialchars
。
问题是,当我echo
没有变量时htmlentities
,它会按原样输出字符串,但是当我echo
变量 WITH时htmlentities
,它什么也不输出。
代码:
这有效:
<h2><?php echo $row['title']; ?></h2>
<p><?php echo $row['description']; ?></p>
这不起作用:
<h2><?php echo htmlentities($row['title']); ?></h2>
<p><?php echo htmlentities($row['description'], ENT_COMPAT, "UTF-8"); ?></p>