我有一个 UCS-2 文本文件。现在,我想将此文本文件作为 UTF-8 字符串读取。我已经使用此代码来执行此操作。
my_code.php:
<?php
error_reporting(0);
header('Content-Type: text/html; charset=utf-8');
echo '<form enctype="multipart/form-data" method="post"><p><input type="file" name="my_file" /> <input type="submit" value="+" /><hr />';
$my_str = file_get_contents(($_FILES['my_file']['tmp_name']));
echo $my_str;
?>
viet_test.txt:
"Vietnamese" is "Tiếng Việt".
但是,它返回错误:��"Vietnamese" is "Ti�ng Vi�t".
。这就是我想要的:("Vietnamese" is "Tiếng Việt"
在 UTF-8 中)。
你能告诉我:“我的代码有什么问题?以及,如何解决它?”。
对不起,我对 PHP 不是很专业。