[英]PHP line break br with ENT_QUOTES
是否可以使用ENT_QUOTES并仍然使用任何方法来打破常规?
$title = htmlentities($_REQUEST['title'], ENT_QUOTES);
例如,当我在字段中输入时:
<input type="text" value="Teacher: Don't cheat at the exam<br /> 1. Rule<br /> 2. Rule<br /> 3. Rule">
它通常必须如下所示:
Teacher: Don't cheat at the exam
1. Rule
2. Rule
3. Rule
但是我得到这个:
Teacher: Don't cheat at the exam<br /> 1. Rule<br /> 2. Rule<br /> 3. Rule
谁能帮我吗?
htmlentities()
本质是将某些字符转换为HTML实体,其中包括<
变为<
和>
变为>
。 ENT_QUOTES
在这里不相关。
因此,如果您使用htmlentities()
来过滤输入(不确定是否应该,也应该指定$_POST
等),那么如果您希望HTML能够正常工作,则应该使用相反的函数将其输出:
例:
$title = htmlentities($_POST['title']);
...
echo html_entity_decode($title); // outputs proper HTML
但是,由于没有更多的上下文,该示例没有意义,并且几乎可以肯定,在您的项目中有更好的方法来执行此操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.