Bonjour,
J'ai un problème concernant un fichier .txt (codage
UTF-8 à la base) que j'édite via un simple formulaire, seulement lorsque je valide mon texte il
retourne au format ANSI.
Si j'ai besoin qu'il reste en UTF-8 c'est dans l'optique qu'une animation swf puisse lire les accents de ce texte dans un champs dynamique standard appelé à l'aide de
this.texteur.loadVariables("texte.txt"); sous flash.
Donc y a t-il un code pour permettre à mon fichier de rester un UTF-8?
Voici mon code très simple car je débute en php pour éditer ce texte: (
act.php)
Code PHP :
<?php
$ressource_fichier = fopen('texte.txt', 'w');
if($ressource_fichier AND is_writable('texte.txt'))
{
fputs($ressource_fichier, htmlentities($_POST['description']));;
fclose($ressource_fichier);
}
?>
Et si il y a besoin mon formulaire: (
rec.php)
Code HTML :
<?php
$fichier = file_get_contents('texte.txt');
echo $fichier;
?>
</div>
<form action="act.php" method="post">
<p align="center"><textarea name="description" rows="1" cols="200">textfield=</textarea></p>
<p align="center"><input type="submit" value="Envoyer" /></p>
</form>
J'ai élagement essayé plusieurs solutions insérés ci-dessous mais rien n'y fait, mon fichier retourne toujours en ANSI.
Premier essai
Code PHP :
<?php
header('Content-Type: text/html; charset=utf-8');//Première essai
$ressource_fichier = fopen('texte.txt', 'w');
if($ressource_fichier AND is_writable('texte.txt'))
{
fputs($ressource_fichier, htmlentities($_POST['description']));;
fclose($ressource_fichier);
}
?>
Second essai
Code PHP :
<?php
$ressource_fichier = fopen('texte.txt', 'w');
if($ressource_fichier AND is_writable('texte.txt'))
{
$description=UTF8_encode($description);// Second essai
fputs($ressource_fichier, htmlentities($_POST['description']));;
fclose($ressource_fichier);
}
?>
Troisième essaiCode PHP :
<?php
$ressource_fichier = fopen('texte.txt', 'w');
if($ressource_fichier AND is_writable('texte.txt'))
{
fputs($ressource_fichier, utf8_encode($_POST['description']));; //troisième essai
fclose($ressource_fichier);
}
?>
Dans toute ses tentatives j'ai laissé l'entête :
Code HTML :
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Si quelqu'un pouvait m'aider ou m'indiquer la marche à suivre, j'en serais plus que ravi!!!
Merci par avance