Retour [./iconv.php]
show/hide
0
1 <!--
2 JJL : http://kubuntu.free.fr/TigerWiki/
3 -->
4
5 <html>
6 <head>
7 <title>Change Encoding</title>
8 <meta http-equiv=content-type content="text/html; charset=UTF-8">
9 </head>
10
11 <body>
12 <pre>
13 <?php
14 if (isset($_GET['from']) and isset($_GET['to']))
15 { // convert
16 if ($opening_dir = @opendir("."))
17 {
18 while (false !== ($filename = @readdir($opening_dir)))
19 if (strtolower(strrchr($filename,'.')) == '.txt')
20 {
21 print ("<a href=$filename>".$filename."</a>...");
22 $strin = file_get_contents($filename);
23 $strout = iconv($_GET['from'],$_GET['to'],$strin);
24 if ($strout != FALSE)
25 {
26 $f = fopen($filename,"w");
27 fwrite($f,$strout);
28 fclose($f);
29 print "OK";
30 }
31 else
32 print "KO";
33 print "\n";
34 }
35 }
36 }
37 else
38 { // ask for input encoding
39 print "<h2>Change Encoding</h2>Convert .txt files in current dir from one encoding to UTF-8.<br/>";
40 if (defined("ICONV_IMPL"))
41 {
42 print "Installed : ".ICONV_IMPL." ".ICONV_VERSION;
43 print "<form method=\"get\" action=\"".$_SERVER['SCRIPT_NAME']."\">Input encoding : <input name=from>Output encoding : <input name=to value=\"UTF-8\"><input type=submit value=\"Go !\"></form>";
44 }
45 else
46 {
47 print "ERROR: iconv extention is not installed";
48 }
49 print ("<br/>See supported <a href=http://www.gnu.org/software/libiconv/>encodings</a>");
50 }
51 ?>
52 </pre>
53 <hr/>
54 <div align=right style={font-size:small;}><a href=http://kubuntu.free.fr/blog/>JJL Creation</a></div>
55 </body>
56 </html>
57
58
59