Forum Moderators: coopster

Message Too Old, No Replies

utf-8 character, htmlentities and form

Problem with special characters in form

         

tomda

2:10 pm on Apr 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Character encoding is really not my cup of tea. So I'll to make it short and undestandable.

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

tomda

9:12 pm on Apr 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Could someone explain me why I get two different outputs, should it not be the same? That's odd!


<!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

ergophobe

8:55 pm on Apr 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Perhaps because the input is not utf-8 and var_html_encode is not a function or it's a custom function and you need to either return a value or pass by reference (are you passing by reference?).

So basically, unless you are passing by reference, you aren't encoding $text in the second case, you're just echoing it.