提问人:Вячеслав Прокопченко 提问时间:10/25/2019 更新时间:10/25/2019 访问量:47
PHP错误?逐行转码
PHP BUG? File-By-Line Transcoding
问:
试试这个代码!
<?php
$handle = fopen("./test.txt", "r");
$serachEncoding = 'CP1251';
while (!feof($handle)) {
$buffer = fgets($handle, 4096);
$buffer = iconv("UTF8", "CP1251//TRANSLIT//IGNORE", $buffer);
$charset = mb_detect_encoding($buffer, [$serachEncoding]);
echo $charset;
}
fclose($handle);
如果 $serachEncoding = UTF8 该文件将被逐行读取,并将在每一行上输出其编码
如果$serachEncoding = CP1251 将输出一行及其编码
那么为什么呢?
答:
0赞
Вячеслав Прокопченко
10/25/2019
#1
好的,我是一个 debil,我现在用字符集和显示var_dump变量添加
bool(false)
bool(false)
bool(false)
string(12) "Windows-1251"
评论
$buffer = iconv("UTF8", "CP1251//TRANSLIT//IGNORE", $buffer);
$buffer = iconv("UTF-8", "CP1251//TRANSLIT//IGNORE", $buffer);
Notice: iconv(): Wrong charset..