note 88329 added to function.utf8-encode
| From: | JulioCesar at osu1 dot php dot net | Date: | Tue, 20 Jan 2009 13:08:46 +0000 |
| Subject: | note 88329 added to function.utf8-encode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-149518@lists.php.net to get a copy of this message | ||
With This Script you can convert a lot of files in
subfolders and convert to UTF8 without problems!
I thought about that when I was converting an eclipse
Project to UTF-8 and I loose all the Accentuation O.o
But with this script YOU WILL NOT! ;-)
I Make this based on Aidan Kehoe's Script and webmaster at
asylum-et dot com of http://www.php.net/scandir:
<?php
ini_set("implicit_flush", "on");
ini_set("max_execution_time", 0);
ini_set("register_argc_argv", "on");
ini_set("html_errors", "Off");
function cp1252_to_utf8($str) {
$cp1252_map = array ("\xc2\x80" => "\xe2\x82\xac",
"\xc2\x82" => "\xe2\x80\x9a",
"\xc2\x83" => "\xc6\x92",
"\xc2\x84" => "\xe2\x80\x9e",
"\xc2\x85" => "\xe2\x80\xa6",
"\xc2\x86" => "\xe2\x80\xa0",
"\xc2\x87" => "\xe2\x80\xa1",
"\xc2\x88" => "\xcb\x86",
"\xc2\x89" => "\xe2\x80\xb0",
"\xc2\x8a" => "\xc5\xa0",
"\xc2\x8b" => "\xe2\x80\xb9",
"\xc2\x8c" => "\xc5\x92",
"\xc2\x8e" => "\xc5\xbd",
"\xc2\x91" => "\xe2\x80\x98",
"\xc2\x92" => "\xe2\x80\x99",
"\xc2\x93" => "\xe2\x80\x9c",
"\xc2\x94" => "\xe2\x80\x9d",
"\xc2\x95" => "\xe2\x80\xa2",
"\xc2\x96" => "\xe2\x80\x93",
"\xc2\x97" => "\xe2\x80\x94",
"\xc2\x98" => "\xcb\x9c",
"\xc2\x99" => "\xe2\x84\xa2",
"\xc2\x9a" => "\xc5\xa1",
"\xc2\x9b" => "\xe2\x80\xba",
"\xc2\x9c" => "\xc5\x93",
"\xc2\x9e" => "\xc5\xbe",
"\xc2\x9f" => "\xc5\xb8"
);
return strtr ( utf8_encode ( $str ), $cp1252_map );
}
function rscandir($base="", &$data=array()) {
$array = array_diff(scandir($base), array(".", ".."));
foreach($array as $value) :
if (is_dir($base.$value)) :
//$data[] = $base.$value."/";
$data = rscandir($base.$value."/", $data);
elseif (is_file($base.$value) &&
!eregi(".jpg|.gif|.png|.ttf|.dataModel|.wsdlDataModel
|.project|.jsdtscope|.prefs|.name|.container|
.exe|.bat|.cmd|.src|.dll|.ini|.swf|.fla|.bmp\$",
$value)) : /* where you put the unwanted extensions */
echo "Converting to UTF8 " . $base.$value . "\r\n";
file_put_contents(
$base.$value,
cp1252_to_utf8(
file_get_contents($base.$value)));
endif;
endforeach;
return $data;
}
echo "Type a Folder (With a Slash in end): ";
$folder = trim(fgets(STDIN));
rscandir($folder);
?>
You can put this on windows Dir and put a Batch like this:
@echo off
php -n C:\windows\ConvertUTF8.php
pause
So you can convert your files from any where, just type on
Execute Command Like: ConvertFilesToUTF8
I think this will help everyone! Enjoy ;-)
P.s: I remove the comments becouse the wordwrap
----
Server IP: 69.147.83.197
Probable Submitter: 201.33.246.38
----
Manual Page -- http://www.php.net/manual/en/function.utf8-encode.php
Edit -- https://master.php.net/note/edit/88329
Del: integrated -- https://master.php.net/note/delete/88329/integrated
Del: useless -- https://master.php.net/note/delete/88329/useless
Del: bad code -- https://master.php.net/note/delete/88329/bad+code
Del: spam -- https://master.php.net/note/delete/88329/spam
Del: non-english -- https://master.php.net/note/delete/88329/non-english
Del: in docs -- https://master.php.net/note/delete/88329/in+docs
Del: other reasons-- https://master.php.net/note/delete/88329
Reject -- https://master.php.net/note/reject/88329
Search -- https://master.php.net/manage/user-notes.php