I am reading one Chinese text file (used PHP) with the help of below code :
$myFile = "test.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
print $theData;
test.txt file contents :
PHP是很好的语言。我喜欢这门语言。
我正在开发一个Web应用程序使用PHP。
After executing above mentioned code, I was not getting exact content which is in above mentioned file.
Is there any other way to read such file which contains Unicode characters and print it.
Please provide me your suggestions.
Thanks,
-Pravin
You need to specify an output encoding to match the encoding of the character data you’re reading.
If your text file is UTF-8 encoded, add one of the following
content-typeheaders to the top of your PHP file:if it is UTF-16 encoded, I would use
iconv()to convert it to UTF-8, which has become pretty much the web’s standard encoding: