4

i have these arabic sentence:

نايتيد أمامه عشرة أيام فقط لكي يقرر مستقبل برباتوف في النادي

It must be sent in the url. I tried this approach:

$url = 'http://example.com/?q='.urlencode('نايتيد أمامه عشرة أيام فقط لكي يقرر مستقبل برباتوف في النادي');

The result of that encoding is: %D9%86%D8%A7%D9%8A%D8%AA%D9%8A%D8%AF+%D8%A3%D9%85%D8%A7%D9%85%D9%87+%D8%B9%D8%B4%D8%B1%D8%A9+%D8%A3%D9%8A%D8%A7%D9%85+%D9%81%D9%82%D8%B7+%D9%84%D9%83%D9%8A+%D9%8A%D9%82%D8%B1%D8%B1+%D9%85%D8%B3%D8%AA%D9%82%D8%A8%D9%84+%D8%A8%D8%B1%D8%A8%D8%A7%D8%AA%D9%88%D9%81+%D9%81%D9%8A+%D8%A7%D9%84%D9%86%D8%A7%D8%AF%D9%8A

But the php script is receiving this in the $_GET['q'] querystring:

نايتيد أمامه عشرة أيام Ùقط لكي يقرر مستقبل برباتو٠ÙÙŠ النادي

The php file is UTF-8 encoded. Any ideas?

hakre
  • 193,403
  • 52
  • 435
  • 836
Andres SK
  • 10,779
  • 25
  • 90
  • 152
  • possible duplicate of [What is the proper way to URL encode Unicode characters?](http://stackoverflow.com/questions/912811/what-is-the-proper-way-to-url-encode-unicode-characters) – Lightness Races in Orbit Dec 21 '11 at 14:56
  • How are you outputting the value of `$_GET['q']`? – Wooble Dec 21 '11 at 14:58
  • did you try: utf8_decode($_GET['q']); – Sudhir Bastakoti Dec 21 '11 at 14:59
  • To a web browser? Is the browser set to display the page as utf-8? (The output you're showing is treating your bytes as Windows-1252) – Wooble Dec 21 '11 at 14:59
  • 2
    If the file is encoded in UTF-8 then the encoding part is done correctly. However, you need to convert the encoding of the incoming string to UTF-8 when you *read* the parameter. Use `iconv` or `mb_convert_encoding` for this. Also, `rawurlencode` should be used "by default" instead of `urlencode` unless there is specific reason not to do it. – Jon Dec 21 '11 at 15:00
  • @Sudhir: That won't work because arabic characters do not exist in ISO-8859-1. – Jon Dec 21 '11 at 15:01
  • Did you tried `file_put_contents('test', $_GET['q'])` and open it in editor with utf8 enabled to check if it's really not utf8? – piotrekkr Dec 21 '11 at 15:03

4 Answers4

4

You must urldecode your encoded entities. Furthermore remember that UTF8 and PHP are not a great combination.

Alex van den Hoogen
  • 744
  • 1
  • 5
  • 22
3

As I mention in other question, You should do urlencode the Arabic text

urlencode('كلام-عربي')

And its very important to add the charset code to the head tag of the page, otherwise the link will not work

<meta charset="utf-8">
usama sulaiman
  • 2,013
  • 4
  • 24
  • 37
1

dont use urlencode just use rawurlencode

ahmadMarafa
  • 1,316
  • 1
  • 13
  • 15
0

As I mention in other question, You should do urldecode the Arabic text in URI

echo urldecode(explode('?', $_SERVER['REQUEST_URI'], 2));
Dharman
  • 30,962
  • 25
  • 85
  • 135
Issa Lafi
  • 345
  • 3
  • 3