$_GET doesn't work correctly with Internet Explorer (UTF-8)
I am trying to GET values from url and I have ended up with a problem in IE but all other browsers it works great.
This is my issue:
If text is some UTF-8 text as example:
$x=$_GET['txt'];
echo $x;
I got
???????
only in IE
开发者_运维百科still same problem and this is my all code
<?php
header('Content-Type: text/html; charset=utf-8');
$x=$_GET['id'];
echo $x;
?>
try with this word in id
سسسسسسس
You can put this meta tag inside the <head>
if it's a charset issue (as an alternative to using header
inside PHP):
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
UPDATE
If you're not encoding the value of x
from the URL you should do something like:
<a href="page.php?x=<?php echo urlencode($string)?>">Link</a>
Using your sample text (سسسسسسس), once that's encoded using urlencode
it should like this:
%D8%B3%D8%B3%D8%B3%D8%B3%D8%B3%D8%B3%D8%B3
I got it working by adding a charset meta tag and doing a simple urldecode
:
echo urldecode($_GET['x']);
See screenshot on IE:
Try setting your page so the browser will recognize its encoding correctly. Mostly sending a proper header is enough:
header('Content-Type: text/html; charset=utf-8');
This is for UTF8
but you can send any encoding you want.
As you already stated yourself this could depending on the browsers character encoding settings. Try the utf8-function in PHP like http://www.php.net/manual/de/function.utf8-decode.php and http://www.php.net/manual/de/function.utf8-encode.php (:
Also look here: Handling unicode values in GET parameters with PHP
try adding: urlencode
& urldecode
around your $x
精彩评论