-4
を使用してファイルのエンコーディングを検索する私はPHPを使用してファイルのエンコーディングを見つけようとしていますが、私はカントは、解決策を得るように見える私はリストから検出するために、次のコードを使用した溶液どのようにPHP
がありますエンコーディングの
public function detect($filePath)
{
$fopen=fopen($filePath,'r');
$row = fgets($fopen);
$encodings = mb_list_encodings();
$encoding = mb_detect_encoding($row, "UTF-8, ASCII, Windows-1252, Windows-1254, Windows-1255");//these are my favorite encodings
if($encoding !== false) {
$key = array_search($encoding, $encodings) !== false;
if ($key !== false)
unset($encodings[$key]);
$encodings = array_values($encodings);
}
$encKey = 0;
while ($row = fgets($fopen)) {
if($encoding == false){
$encoding = $encodings[$encKey++];
}
if(!mb_check_encoding($row, $encoding)){
$encoding =false;
rewind($fopen);
}
}
return $encoding;
}
これまでに何を試しましたか? – Thamaraiselvam
はい、可能です。あなたは何か、Googleのためにそれを試してみましたか? – Qirel
上記のコードを確認してください@Qirel – Dan