php:如何:echo"<input value ='{$ test}'>"; 与$ test ="(亜)(')(\")";?

ajo*_*ajo 2 html php quotes utf-8

<?php
$info = " ? and ' and \" ";
$info=str_replace(array("'","\""),array("&#39;","&#34;"),$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 没有)

Sar*_*raz 8

您需要指定第三个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