Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$_GET encoding problem with cyrillic text

Tags:

I'm trying this code (on my local web server)

<?php
echo 'the word is / думата е '.$_GET['word'];
?>

but I get corrupted result when enter ?word=проба

the word is / думата е ����

The document is saved as 'UTF-8 without BOM' and headers are also UTF-8. I have tried urlencode() and urldecode() but the effect was same. When upload it on web server, works fine...

like image 466
T1000 Avatar asked Mar 07 '10 21:03

T1000


1 Answers

What if you try sending a HTTP Content-type header, to indicate the browser which encoding / charset your page is generating ?

For instance, something like this might help :

header('Content-type: text/html; charset=UTF-8');
echo 'the word is / думата е '.$_GET['word'];

Of course, this is if you are generating HTML -- you probably are.


Considering there is a configuration setting at the server's level that defines which encoding is sent by default, maybe the default encoding on your server is OK -- while the one on your local server is not.

Sending such a header by yourself would solve the problem : it would make sure the encoding is always set properly.

like image 94
Pascal MARTIN Avatar answered Sep 28 '22 04:09

Pascal MARTIN