[英]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.