Question

If I run this from a PHP script in a browser:

echo imap_utf8('X-My-Custom-Header: =?UTF-8?B?RXVnZW4gQmFiacSH?=');

I get this:

X-My-Custom-Header: Eugen BabicÌ

However if I do it through the PHP interactive shell, it correctly returns:

php > echo imap_utf8('X-My-Custom-Header: =?UTF-8?B?RXVnZW4gQmFiacSH?=');
X-My-Custom-Header: Eugen Babić

I have a script set up on the internet using a few decoding functions here: http://cameronsflash.com/misc/test.php as you can see none of them correctly decode the string (but in the interactive shell they do).

Why is it different in the browser and how do I fix it?

Edit: For some reason the accent on the c is not being displayed in the second example, but it is there in the console.

Était-ce utile?

La solution

Here's what you're doing wrong: You're HTML (as generated by the PHP) is not UTF-8 encoded.

Add this to your <head>

tag:

<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top