开发者

PHP accented characters in POST submit

I have a HTML form on submit.php, the page is encoded as UTF-8 (using a meta tag), when the form is submitted to process.php (via POST), some of the variables are stored in the session, and the page uses Header: Location to go back to submit.php, which then uses the session variables to redisplay some of the entered information.

If I enter an accented character, for example é (&eacute), when the page returns to submit.php, it does not render the character correctly, I get an ã (&atilde) and an © (&copy) instead.

Where should I be looking to solve this problem? I'm assuming it's server side, as the rendered page is always UTF-8 (the browser confirms the page is UTF-8 before and after submitting)

Solutio开发者_StackOverflow中文版n:

The string was being passed through htmlentities() at one point, which it turns out has a default character encoding of ISO-8859-1 The answer was to simply specify 'UTF-8' in the function call.


é being turned into is a sure-fire sign that the 2-byte UTF-8 character at some point gets interpreted in a 1-byte character set (most likely ISO-8859-1).

You need to find where this happens, and fix it.

Maybe show some code - maybe somebody has an idea.


$_SESSION['thestring'] = $_POST['thestring']

Cannot reasonably be the problem source. Here PHP is just copying the two bytes verbatim. No charset conversion is going to occour here. Hence any conversion likely happened before or thereafter.

To make sure $_POST isn't the cultprit, check that your <form> contains the accept-charset="UTF-8". That's often overlooked. Second, for testing purposes output the $_POST["thestring"] right on receival. If the problem arises here, you'll need Firebug and xdebug..

It's very unlikely that the session store or PHP modify the string contents in $_SESSION. That's why I would presume the bug to be in the output page after all. Make a separate test page, and print $_SESSION["thestring"] there. Don't overlook the header("Content-Type: text/html; charset=utf-8"); for it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜