I Have Created A simple Chat script m using mysql fetch array to show the text written by users but a lot of users using html codes in text box and Changing my site configs [like Text color adding Images] please help me how to show the entered Html code as plaintext ?
问问题
690 次
4 回答
6
在输出文本之前使用htmlspecialchars()或htmlentities():
$message = htmlspecialchars($message);
echo $message;
这将转换特殊字符,以便将它们打印到屏幕上,而不是作为 HTML 处理。
Strip_tags() 将它们一起删除,不是最优的。
于 2013-07-08T15:49:04.520 回答
1
您可以通过以下几种方式禁用此功能:
html_entities($message);
将标签符号更改为字符代码,以便它们显示为字符但没有功能(可能是最好的方法)strip_tags($message);
完全删除任何标签符号
我希望这有帮助!
于 2013-07-08T16:20:51.857 回答
1
你可以使用htmlentities()
它。
它的作用的一个例子:
<?php
$str = "A 'quote' is <b>bold</b>";
// Outputs: A 'quote' is <b>bold</b>
echo htmlentities($str);
// Outputs: A 'quote' is <b>bold</b>
echo htmlentities($str, ENT_QUOTES);
?>
于 2013-07-08T15:49:44.830 回答
-1
您将要使用strip_tags();
删除聊天消息的 HTML 格式
于 2013-07-08T15:46:46.807 回答