php: how to: echo "<input value='{$test}'>"; with $test=" (亜) (') (\") ";?
<?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}' >";
?>开发者_如何学编程;
This works, BUT: Is there a tidier method like $info=htmlentities($info,ENT_QUOTES)
which preserves the UTF-8 display? (htmlentities doesn't)
You need to specify third utf-8
parameter:
$info = htmlentities($info, ENT_QUOTES, 'UTF-8');
From Docs:
Like htmlspecialchars(), it takes an optional third argument charset which defines character set used in conversion. Presently, the ISO-8859-1 character set is used as the default.
Source: http://php.net/manual/en/function.htmlentities.php
精彩评论