Retour [test_charset/index.php5]
show/hide
0
1 <!--
2 Test des conversions d'encodage de caractères
3 -->
4
5 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
6         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
7 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
8 <head>
9     <meta http-equiv="content-type" content="text/html; charset=utf-8" />
10     <title>Test encodage pour TigerWiki - JJL</title>
11 </head>
12
13 <body>
14
15 <h1>Test UTF-8</h1>
16 <hr/>
17 <pre>
18 <?php
19
20
if (!function_exists("mb_detect_encoding"))
21 {die (
"module mbstring non install&eacute;");}
22
23
$fname="test_utf.txt";
24
25
// ordre de detection
26
mb_detect_order(array("UTF-8","ISO-8859-1"));
27
print_r (mb_detect_order());
28
29 if (isset(
$_POST['content']))
30
// write file
31    
print "INPUT:".mb_detect_encoding($_POST['content'])."\n";
32    
$f fopen($fname,"w");
33    
fputs($f,mb_convert_encoding($_POST['content'],"UTF-8",mb_detect_encoding($_POST['content'])));
34    
fclose($f);
35 }
36
37 if (isset(
$_POST['file']))
38 {
39    if (
$_POST['file'] == "iso")
40       
$fname .= "-iso";
41    else
42       
$fname .= "-utf";
43 }
44
45 if (
file_exists($fname))
46 {
47    print 
"reading: ".$fname."<br/>";
48    
$f fopen($fname,'r');
49    
$CONTENT fread($ffilesize($fname));
50    
fclose($f);
51 }
52
53
// conversions
54
print "CONTENT:".mb_detect_encoding($CONTENT)."\n";
55
56
$CONTENT mb_convert_encoding($CONTENT,"UTF-8",mb_detect_encoding($CONTENT));
57
58
// affichage
59
print "</pre>\n<hr/><h2>Affichage</h2>\n".$CONTENT;
60
61
// form de saisie
62
echo "\n<hr/>\n<h2>Entrée du script</h2><table><tr><td>";
63 echo 
"<h3>Texte</h3><form action=".$_SERVER['SCRIPT_NAME']." method=POST>";
64 echo 
"<textarea name=\"content\" >".$CONTENT."</textarea><br/>";
65 echo 
"<input type=submit value=Ecrire>";
66 echo 
"</form></td><td><form action=".$_SERVER['SCRIPT_NAME']. " method=POST>";
67 echo 
"<h3>Fichier</h3><br/><input type=radio name=file value=utf> UTF-8<br/>\n";
68 echo 
"<input type=radio name=file value=iso> ISO-8859-1<br/>\n";
69 echo 
"<input type=submit value=Lire>\n";
70 echo 
"</form></td></tr></table>\n";
71
72
73
?>
74

75 </body>
76 </html>

77