0

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

سسسسسسس

Samy Massoud
  • 4,295
  • 2
  • 35
  • 48

4 Answers4

2

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: enter image description here

tradyblix
  • 7,439
  • 3
  • 25
  • 29
  • amazing but what if i want to put this into sql search routine that contain % ? ? ? – Samy Massoud May 19 '11 at 12:06
  • you need to somehow decode it before feeding it to your SQL query e.g. assuming you're using simple query `$search = mysql_real_escape_string(urldecode($_GET['x']));` something like that. – tradyblix May 19 '11 at 12:13
  • i will mark this as best answer because you put me on the right way and i use this with my app jquery ajax based :D – Samy Massoud May 19 '11 at 13:07
1

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.

Jan Zyka
  • 17,460
  • 16
  • 70
  • 118
0

try adding: urlencode & urldecode around your $x

Mike Mackintosh
  • 13,917
  • 6
  • 60
  • 87
metaforce
  • 1,337
  • 5
  • 17
  • 26
  • didn't understood you quite well, try using these functions: http://php.net/manual/en/function.utf8-encode.php && http://php.net/manual/en/function.utf8-decode.php ... and also encode your files with UTF-8, and add the content-type in your HTML META tags – metaforce May 19 '11 at 11:11
0

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

Community
  • 1
  • 1
tim
  • 9,896
  • 20
  • 81
  • 137