I am using PHP,Python and MySQL on a Macbook with OS10.10.5. I have the following sentence stored in MySQL:

However, when I use Python or MySQL to retrieve that string, it comes out as:
محمود السقا لـCNN: النظام يؤدب ثورة يناير
i.e. the letters and words get shunted around, e.g. the very first letter on the left hand side - in the original text its to the right of the CNN.
When I cut-and-paste from MySQL into TextEdit it comes out fine?!
I only seem to get this problem when I have any non-Arabic characters (e.g. C N N ") in my string???
Any advice appreciated.
Thanks.
when I use Python or MySQL to retrieve that string, it comes out as: محمود السقا لـCNN: النظام يؤدب ثورة يناير
because the browser(or what ever it is drawing the letters) is using LTR direction
When I cut-and-paste from MySQL into TextEdit it comes out fine?!
because your TextEdit is using RTL direction
Example-1
(RTL)
"أحب من الإنجليزية كلمة "SUN" وهي تعني الشمس" (LTR)
Example-2
"from the Arabic language I like the word "شمس" which means the sun" (LTR)
(RTL)
technically, the browser didn't do anything wrong, he just draw the letters he encounters in the string one after another according to the text direction he is using, only the human reader will be confused.
when you displayed the string using the browser, the browser was using LTR context, so this is what happened:
1- the browser starts to draw the characters he encounters "محمود السقا لـ". from left to right. this first part is all in Arabic, so far so good.
2- now the browser encounters the word "CNN" he draws it also from left to right -the browser doesn't know which language he is drawing, he just draw characters using the context you have chosen-
now the string is shown like this
"محمود السقا لـ" + "CNN"
3- the browser encounters the last part which is "النظام يؤدب ثورة يناير", he draws it also from left to right without any awareness which characters are those! , now the displayed text is shown like this
"محمود السقا لـ" + "CNN" + "النظام يؤدب ثورة يناير"
SUMMERY when you combine multiple directions languages in one text, use the right context that will result in a better view for the human reader
LTR


RTL


If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With