Problème de gestion des accents
Bonjour,
J'apporte une dernier petite retouche a mes codes concernant les carractères avec accent
J'ai mes tables qui sont en utf8 et inteclassement en utf8_general_ci
J'utilise un formulaire afin de mettre un champs à jour dans ma tables échange voir ci-dessous
Code:
1 2 3 4 5 6 7 8
|
CREATE TABLE IF NOT EXISTS `echange` (
`echang_id` varchar(6) NOT NULL,
`echang_observation` longtext NOT NULL,
`date_jour` varchar(10) NOT NULL,
`echang_interlocuteur` text NOT NULL,
PRIMARY KEY (`echang_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; |
Dans le formulaire (un textarea), j'utilise une fonction pour géré les BBcode
Ma fonction de codage
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
<?php
function code($document)
{
$document = htmlentities($document, ENT_QUOTES,UTF-8);
//Mise en forme du texte
//gras
$document = preg_replace('`\[g\](.+)\[/g\]`isU', '<strong>$1</strong>', $document);
//italique
$document = preg_replace('`\[i\](.+)\[/i\]`isU', '<em>$1</em>', $document);
//souligné
$document = preg_replace('`\[s\](.+)\[/s\]`isU', '<u>$1</u>', $document);
//lien
$document = preg_replace('#http://[a-z0-9._/-]+#i', '<a href="$0">$0</a>', $document);
//quote
$document = preg_replace('`\[quote\](.+)\[/quote\]`isU', '<div id="quote">$1</div>', $document);
//taille
$document = preg_replace('`\[taille=(.+)\](.+)\[/taille\]`isU', '<span style="font-size:$1px">$2</span>', $document);
// Remplacement des sauts de ligne par des <br />
$document = nl2br($document);
//On retourne la variable texte
return ($document);
}
?> |
fichier de traitement des données pour l'insertion
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
<?php
session_start ();
ini_set ("error_reporting", "E_ALL & ~E_NOTICE");
echo "<a href='../index.php'>Retour index</a>";
include('../inc/inc_connexion.php');
include ('../inc/fonction.php');
//***********************************************************************
if(isset($_POST['numero']) AND $_POST['numero']!= NULL
AND isset($_POST['observation']) AND $_POST['observation']!= NULL)
{
$numero= $_POST['numero'];
$observation= code(htmlentities($_POST['observation']));
$utilisateur=$_SESSION['pseudo'];
$requete ="INSERT INTO echange values('".$numero."','".$observation."','".date("Y-m-d")."','".$utilisateur."')";
$req = mysql_query( $requete ) or die(mysql_error());
header('location:../vues/fiche_pdv_complet.php?numero='.$numero.'');
}
?>
<script>
function bbcode(bbdebut, bbfin)
{
var input = window.document.formulaire.observation;
input.focus();
if(typeof document.selection != 'undefined')
{
var range = document.selection.createRange();
var insText = range.text;
range.text = bbdebut + insText + bbfin;
range = document.selection.createRange();
if (insText.length == 0)
{
range.move('character', -bbfin.length);
}
else
{
range.moveStart('character', bbdebut.length + insText.length + bbfin.length);
}
range.select();
}
else if(typeof input.selectionStart != 'undefined')
{
var start = input.selectionStart;
var end = input.selectionEnd;
var insText = input.value.substring(start, end);
input.value = input.value.substr(0, start) + bbdebut + insText + bbfin + input.value.substr(end);
var pos;
if (insText.length == 0)
{
pos = start + bbdebut.length;
}
else
{
pos = start + bbdebut.length + insText.length + bbfin.length;
}
input.selectionStart = pos;
input.selectionEnd = pos;
}
else
{
var pos;
var re = new RegExp('^[0-9]{0,3}$');
while(!re.test(pos))
{
pos = prompt("insertion (0.." + input.value.length + "):", "0");
}
if(pos > input.value.length)
{
pos = input.value.length;
}
var insText = prompt("Veuillez taper le texte");
input.value = input.value.substr(0, pos) + bbdebut + insText + bbfin + input.value.substr(pos);
}
}
function smilies(img)
{
window.document.formulaire.message.value += '' + img + '';
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
<head>
<title>Gestion des dus</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<body>
<form method="POST" action="creer_commentaire_societe.php" name="formulaire" accept-charset="UTF-8">
<fieldset><legend>Mise en forme</legend>
<input type="button" id="gras" name="gras" value="Gras" onClick="javascript:bbcode('[g]', '[/g]');return(false)" />
<input type="button" id="italic" name="italic" value="Italic" onClick="javascript:bbcode('', '');return(false)" />
<input type="button" id="souligné" name="souligné" value="Souligné" onClick="javascript:bbcode('', '');return(false)" />
<input type="button" id="taille" name="taille" value="Taille" onclick="javascript:bbcode('[taille=18px]', '[/taille]');return(false)" />
<br/><br/>
<textarea cols="115" rows="10" name="observation"></textarea><br>
<input type="text" name="numero" value="<?php echo $_GET['numero'];?>" size='7'>
<br />
<input type="submit" name="submit" value="Envoyer" />
<input type="reset" name="Effacer" value="Effacer" /></p>
</fieldset>
</form>
</body>
</html> |
Ma page d'affichage du résulta avec mie en forme
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
<?php
session_start();
ini_set ("error_reporting", "E_ALL & ~E_NOTICE");
include('../inc/inc_connexion.php');
if(!empty($_GET['numero']))
{
$numero=$_GET['numero'];
$sql = "SELECT COUNT(echang_id) as nb_commentaire, echang_id, echang_observation FROM echange WHERE echang_id = $numero";
$requete = mysql_query( $sql) or die( "ERREUR MYSQL numéro: ".mysql_errno()."<br>Type de cette erreur: ".mysql_error()."<br>\n" );
while( $result = mysql_fetch_assoc( $requete) )
{
//*********************************************************************************************************//
// Affichage conditionnel du lien Création ou modification des commentaire //
//*********************************************************************************************************//
if ($result['nb_commentaire'] ==1)
{
echo "<a href='../modele/commentaire_societe.php?numero=$numero'>Mise à jour des commentaires</a>";
}
else
{
echo "<a href='../modele/creer_commentaire_societe.php?numero=$numero'>Ajouter un premier un commentaire</a>";
}
//********************************************************************************************************//
//récupération avec mysql_fetch_assoc(), et affichage de nos résultats :
echo( "<table BORDER=1 BORDERCOLOR=#CCCCCC BGCOLOR=#fffccc CELLSPACING=0 CELLPADDING=1 WIDTH=950 ALIGN=left>\n" );
echo( "<tr>
<td bgcolor='#669999'><div align=\"center\">Commentaire</div></td></tr>" );
$obs = $result['echang_observation'];
echo "<tr>\n" ;
echo "<td>".htmlspecialchars_decode($result['echang_observation'])."</td>\n" ;
echo "</tr>\n";
}
echo "</table><br>\n" ;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
<head>
<title>Gestion des dus</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<body>
</body>
</html> |
Résultat obtenu lors de l'insertion en dans a table
Code:
1 2
|
<em>test des &Atilde;&copy; &Atilde;&nbsp; et &Atilde;&sup1; dans un &Atilde;&sect;a</em> |
Résultat lors de l'affichage à l'écran
Code:
1 2
|
test des é à et ù dans un ça |
Malgré des recher sur google j'ai pas pu résoudre ce problème
Je vous remerci de l'aide que vous pourriez m'apporter
Runcafre91