Sending arabic characters in URL

10,248

Solution 1

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

Solution 2

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">

Solution 3

dont use urlencode just use rawurlencode

Share:
10,248
Andres SK
Author by

Andres SK

Updated on June 04, 2022

Comments

  • Andres SK
    Andres SK almost 2 years

    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?

    • Lightness Races in Orbit
      Lightness Races in Orbit over 12 years
    • Wooble
      Wooble over 12 years
      How are you outputting the value of $_GET['q']?
    • Sudhir Bastakoti
      Sudhir Bastakoti over 12 years
      did you try: utf8_decode($_GET['q']);
    • Wooble
      Wooble over 12 years
      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)
    • Waihon Yew
      Waihon Yew over 12 years
      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.
    • Waihon Yew
      Waihon Yew over 12 years
      @Sudhir: That won't work because arabic characters do not exist in ISO-8859-1.
    • piotrekkr
      piotrekkr over 12 years
      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?
  • hakre
    hakre over 12 years
    Huh? PHP and UTF8 are not a great combination? Why do you say so?