Risposte:
A partire dal StackOverflow :
You can get a tool such as iconv from GnuWin32 and run a batch script to process all of your files that way. But what encoding are they now? If they're ANSI, and you're not using any bytes with values => 128, then they're already BOM-less UTF-8. Perhaps you can use that to narrow down the number of files you'd have to process - maybe enough that you only have a few files to convert (and might prefer to do it on an individual basis).
Actually, I do it with Notepad++. Before trying this, you must make a backup of your files. You need to create a macro that does this:Ora apri il tuo
- Converti il file attualmente aperto in UTF-8 senza BOM;
- Seleziona tutto il testo nel tuo file e copialo (perché questo? sembra un insetto se non lo farai, il tuo file verrà sostituito con il tuo attuale contenuto degli appunti ...);
- Salva il file corrente;
- Chiudi il file corrente.
- Salva questa macro.
PHPfile ed eseguirlo con "Esegui una macro multipla Volte ... ". Se hai aperto 100 file, fallo funzionare per 100 volte.
<?php
$url = getenv("SERVER_ADDR");
//$url = getenv(HTTP_POST_VARS);
$rootdir='d:\\xampp\\htdocs\\ecoder';
$dir=".";
$files=scan_dir($rootdir);
foreach ($files as $file) {
$info = pathinfo($file);
$extF =$info["extension"];
if ($extF == "php" || $extF == "txt" || $extF == "js" || $extF == "css") {
echo $file ."
";
$ data = file_get_contents ($ file);
writeUTF8File ($ file, $ data);
echo $ file. ' è stato convertito in UTF8
';
}
}
// usa questa funzione per ottenere tutti i file all'interno di una directory (incluse le sottodirectory)
function scan_dir ($ dir) {
$ arrfiles = array ();
se (is_dir ($ dir)) {
if ($ handle = opendir ($ dir)) {
chdir ($ dir);
while (false! == ($ file = readdir ($ handle))) {}
if ($ file! = "." & amp; & amp; $ file! = "..") {
if (is_dir ($ file)) {
$ arr = scan_Dir ($ file);
foreach ($ arr come $ valore) {
$ arrfiles [] = $ dir. "/". $ valore;
}
} altro {
$ arrfiles [] = $ dir. "/". $ file;
}
}
}
chdir ( "../");
}
closedir ($ handle);
}
restituire $ arrfiles;
}
function writeUTF8File ($ filename, $ content) {// บันทึก ไฟล์ เป็น UTF8
$ F = fopen ($ filename, "w");
# Ora UTF-8 - Aggiungi contrassegno ordine byte
fwrite ($ f, pack ("CCC", 0xef, 0xbb, 0xbf));
fwrite ($ f, $ content);
fclose ($ f);
}
? & Gt;