Sending arabic characters in URL
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
Andres SK
Updated on June 04, 2022Comments
-
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 over 12 yearspossible duplicate of What is the proper way to URL encode Unicode characters?
-
Wooble over 12 yearsHow are you outputting the value of
$_GET['q']
? -
Sudhir Bastakoti over 12 yearsdid you try: utf8_decode($_GET['q']);
-
Wooble over 12 yearsTo 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 over 12 yearsIf 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
ormb_convert_encoding
for this. Also,rawurlencode
should be used "by default" instead ofurlencode
unless there is specific reason not to do it. -
Waihon Yew over 12 years@Sudhir: That won't work because arabic characters do not exist in ISO-8859-1.
-
piotrekkr over 12 yearsDid 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 over 12 yearsHuh? PHP and UTF8 are not a great combination? Why do you say so?