我有一个输入,用户可以输入其html,稍后将其显示为正文的一部分。为了确保正确输入用户输入的html,我正在使用以下代码:
$dom = new DOMDocument();
libxml_use_internal_errors(true);
$dom->loadHTML($body);
$dom->removeChild($dom->doctype);
$body = $dom->saveHTML();
$body = str_replace('<html><body>', '', $body);
$body = str_replace('</body></html>', '', $body);
$body = trim(preg_replace('/\s\s+/', ' ', str_replace("\n", " ", $body)));
现在,如果用户输入的内容包含双引号(“)或单引号,这会将其转换为类似“
的形式,并在html中显示为“
。如何确保引号等特殊字符正确显示?
编辑: 这是粘贴的文本示例:
It is called a “buddy list,” “friend list” or “contact list." Users are typically alerted when someone on their list is online.
正在转换为:
It is called a “buddy list,†“friend list†or “contact list." Users are typically alerted when someone on their list is online.
答案 0 :(得分:0)
尝试
sort