Why Not ? a deep breath and let yourself fall out of life

24Nis/092

iso dan utf-8 e geçiş…

İhtiyacımız olabilir bazen oluyor...

$ourTree = rscandir();
$onlyFiles = array();
foreach ($ourTree as $file) {
if (!is_dir($file)) {
if (!preg_match('%/\.svn%', $file)) {
$mimecontenttype = mime_content_type($file);
if ($mimecontenttype == 'text/plain') {
$encoding      = mb_detect_encoding(file_get_contents($file), 'UTF-8, ISO-8859-9, ISO-8859-1');
$result      = mb_convert_encoding( $file, 'UTF-8', 'ISO-8859-9');
$iconv          = file_put_contents($file, iconv("ISO-8859-9", "UTF-8", file_get_contents($file)));
$onlyFiles[] = array(
'file' => $file,
'currentEncoding' => $encoding,
'result' => $result,
'mime' => $mimecontenttype,
'iconv' => $iconv,
'test' => mb_detect_encoding(file_get_contents($file), 'UTF-8, ISO-8859-9, ISO-8859-1')
);
}
}
}
}
print_r($onlyFiles);

Kategori: PHP Yorum gönder.
Yorumlar (2) Geri izlemeler (1)
  1. Keşke bu yazıyı daha önce görseydim.
    Başıma bir sürü işler açmadan:)

  2. :) Linux veya Mac üzerinde shell yetkin varsa

    #!/bin/sh

    for file in *.txt; do
    iconv -f WINDOWS-1251 -t UTF-8 $file> tmp.txt;
    mv tmp.txt $file
    echo $file
    done

    da işini görecektir. Bu arada fark ettim ki siteme özen göstermeliyim :D


Yorum gönder.