Forum Moderators: coopster
I have a simle form with one particular text input (called "test"). I send the form (method POST), get and check the variable ($test=$_POST["test"]) and I then use the htmlentities function to encode the $test in utf-8.
If there are some errors, the form is returned and the $test value is shown in the text input. I DO NOT use html_entity_decode.
Everything works great (meaning that " is written " in the page source and appears as " in the form OR that ' is writtent ' in the page source and appears as ' in the form)
EXCEPTED FOR
special character like é, à, ç, etc... which looks like ç, è, Ã, etc... in my form
Any idea what I can do to avoid this?
Thank you
<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0 Transitional//EN'>
<html>
<head>
<title>Test utf-8</title>
<meta http-equiv='Content-Type' content='text/html;charset=utf-8'>
</head>
<body><?php
function var_html_encode ($varia) {
$varia=rtrim($varia);
$varia=ltrim($varia);
$varia=str_replace("<br>","\r\n",$varia);
$varia=htmlentities($varia,ENT_QUOTES);
return $varia; }$text="ç&é'((--èè_çà";
echo htmlentities($text,ENT_QUOTES);echo "<br>";
$text="ç&é'((--èè_çà";
var_html_encode($text);
echo $text;?>
</body>
</html>
Thank you
So basically, unless you are passing by reference, you aren't encoding $text in the second case, you're just echoing it.