ajo*_*ajo 2 html php quotes utf-8
<?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}' >";
?>
Run Code Online (Sandbox Code Playgroud)
这工作,但:有没有像一个整洁的方法,$info=htmlentities($info,ENT_QUOTES)它保留了UTF-8的显示?(htmlentities 没有)
您需要指定第三个utf-8参数:
$info = htmlentities($info, ENT_QUOTES, 'UTF-8');
Run Code Online (Sandbox Code Playgroud)
来自Docs:
像用htmlspecialchars(),它有一个可选的第三个参数的字符集,其限定在转换中使用的字符集.目前,ISO-8859-1字符集用作默认值.
资料来源: http ://php.net/manual/en/function.htmlentities.php