note 88329 deleted from function.utf8-encode by cmb

From: Date: Sun, 04 Dec 2016 12:14:03 +0000
Subject: note 88329 deleted from function.utf8-encode by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-208202@lists.php.net to get a copy of this message
Note Submitter: Julio Cesar ---- 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

« previous php.notes (#208202) next »