我有一个 HTML 表单,它在ISO-8859-1中设置。现在,我想将UCS-2
字符串转换为UTF-8
字符串;此输出UTF-8
将打印到<input type="text" name="out" />
. 并且,我的 HTML 表单中的字符集不得更改。
我已经阅读了这些问题:
我尝试通过以下代码解决我的问题:
<?php $str = $_POST['str']; ?>
<form method="post">
<input type="text" name="str" value="<?php echo $str; ?>" />
<input type="submit" />
</form>
<hr /><input type="text" name="out" value="<?php echo mb_convert_encoding($str, 'UCS-2', 'UTF-8'); ?>" />
当我在UCS-2中输入一个单词时,例如:Việt Nam
,它将返回:�V�i�&�#�7�8�7�9�;�t� �N�a�m
。为什么?
有没有办法通过 PHP 将 UCS-2 转换为 UTF-8;然后,输出到<input type="text" name="out" />
?