<?php
$info = " 亜 and ' and \" ";
$info=str_replace(array("'","\""),array("'","""),$info);
echo "<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>";
echo "<input id=info name=info value='{$info}' >";
?>
这有效,但是:是否有一种比$info=htmlentities($info,ENT_QUOTES)
更整洁的方法保留 UTF-8 显示? (htmlentities 不)
答案 0 :(得分:8)
您需要指定第三个utf-8
参数:
$info = htmlentities($info, ENT_QUOTES, 'UTF-8');
来自文档:
与htmlspecialchars()一样,需要一个 可选的第三个参数charset 定义中使用的字符集 转换。目前,ISO-8859-1 字符集用作默认值。