problem with encode (charset) .. please help

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
ScOrPi
Forum Commoner
Posts: 44
Joined: Fri Jul 09, 2010 8:01 am
Location: BAGHDAD - IRAQ

problem with encode (charset) .. please help

Post by ScOrPi »

Dear All,

i've biiiiiig problem .. i was learning ajax and i know big side of it ..

my problem is .. that when someone comment the comment would be unable to read till he refresh the page that's mean .. i do nothing with ajax .. he need to refresh again ..

i'm using arabic langauge .. and windows-1256 encode(charset) for all pages .. including the . js page ..

is there any solution ?

i think that :

Code: Select all

document.getElementById("result").innerHTML = xmlHttp.responseText;
it's javascript code not php code .. :?

taking ������ xmlHttp.responseText as utf-8 !

so how could i make that object with id "result" get the value with windows-1256 ?
User avatar
PHPHorizons
Forum Contributor
Posts: 175
Joined: Mon Sep 14, 2009 11:38 pm

Re: problem with encode (charset) .. please help

Post by PHPHorizons »

Hello ScOrPi,
ECMAScript Language Specification wrote:When a String contains actual textual data, each element is considered to be a single UTF-16 code unit.
Therefore, you should convert the character encoding from windows-1256 to UTF-16 before sending that string to the JavaScript.

Cheers
ScOrPi
Forum Commoner
Posts: 44
Joined: Fri Jul 09, 2010 8:01 am
Location: BAGHDAD - IRAQ

Re: problem with encode (charset) .. please help

Post by ScOrPi »

PHPHorizons wrote:Hello ScOrPi,
ECMAScript Language Specification wrote:When a String contains actual textual data, each element is considered to be a single UTF-16 code unit.
Therefore, you should convert the character encoding from windows-1256 to UTF-16 before sending that string to the JavaScript.

Cheers
thanks for reply ..

but i'm using javascript linked with php .. to insert into mysql tables ..

if i used uft-16 .. then the inserted text would be chaset with utf 16 .. and my script run on windows-1256

that would make another problem wich is unreadable charecters ..

so .. if i used (utf-16) for JS .. is there any function to change the charset mode in php to windows-1256 ?

and if there is a function ... and it's worked i still have the same problem .. is there a function to change the charset from utf 16 to windows-1256 in JS ?

i can make it just utf .. but abaric users set them web browser to windows-1256 !
User avatar
PHPHorizons
Forum Contributor
Posts: 175
Joined: Mon Sep 14, 2009 11:38 pm

Re: problem with encode (charset) .. please help

Post by PHPHorizons »

Fortunately for you, users do not determine the character encoding of a website. You do. The only reason a browser would default to something other than the encoding you want is because you did not specify the encoding with a meta tag, or the html file is not saved using that encoding.

I have done sites for arabic users. The way to do it is shift everything to utf-8. Make sure all files are saved using utf-8, all database tables are using utf-8, and your meta tag for character encoding on the website is utf-8. And then you should not have this problem. You will still have the problem of php functions like strlen() returning the wrong string length for multibyte arabic characters though.

There are ways to convert encoding in php, but not in javascript (as far as I know). Therefore, if you are going to do any conversion, always do it on the php side (i.e., the backend).

Cheers
ScOrPi
Forum Commoner
Posts: 44
Joined: Fri Jul 09, 2010 8:01 am
Location: BAGHDAD - IRAQ

Re: problem with encode (charset) .. please help

Post by ScOrPi »

i see .. thanks ..

u mean the solve for problen is change the whole page encode to utf-8 ?

i did that and it works .. but i've user who use google chrome .. he still see squers charecters (arabic doesn't appear for him)

and iam using javascript just to return the value from php -> html page

i mean i have a php page with is insert into database .. and a php page for read from database .. and it works ok (for insert into database)

but when i use javascript to read from database using a remote php script i've unknown charectrs ..

anyway thak you for every thing that's so useful ..

i'm sorry if u'd tired :oops:
ScOrPi
Forum Commoner
Posts: 44
Joined: Fri Jul 09, 2010 8:01 am
Location: BAGHDAD - IRAQ

Re: problem with encode (charset) .. please help

Post by ScOrPi »

by the way could u see this topic ? :mrgreen:

viewtopic.php?f=1&t=120299
User avatar
PHPHorizons
Forum Contributor
Posts: 175
Joined: Mon Sep 14, 2009 11:38 pm

Re: problem with encode (charset) .. please help

Post by PHPHorizons »

i'm sorry if u'd tired
I appreciate your consideration ;) This is a very valid problem that many folks dealing with languages other than English face. I've had to deal with it as well. I'm glad to be of service.
but i've user who use google chrome .. he still see squers charecters (arabic doesn't appear for him)
What happens for you in google chrome? Your user may have been viewing a cached javascript script (or webpage/ajax response), and not the latest one. I would recommend trying it yourself in chrome. If the same web page works in IE and Firefox, but does not work in Chrome, then you may have found a bug in Chrome. It may be worth posting a bug report to Chrome, after you've tested the issue yourself.
but when i use javascript to read from database using a remote php script i've unknown charectrs ..
The best thing I can tell you is that the remote php script may need to call the header() function set a header for the character encoding of the ajax response. It's possible the browser is defaulting to a different character encoding since the ajax response may not have a character encoding specified.

Cheers, hope that helps.
ScOrPi
Forum Commoner
Posts: 44
Joined: Fri Jul 09, 2010 8:01 am
Location: BAGHDAD - IRAQ

Re: problem with encode (charset) .. please help

Post by ScOrPi »

Thank you for ur help and useful notes ..

i appreciate ur help
User avatar
PHPHorizons
Forum Contributor
Posts: 175
Joined: Mon Sep 14, 2009 11:38 pm

Re: problem with encode (charset) .. please help

Post by PHPHorizons »

Sure thing ;)
edaili
Forum Newbie
Posts: 3
Joined: Tue Oct 05, 2010 6:58 am

Re: problem with encode (charset) .. please help

Post by edaili »

Hello
Im having a similiar problem
I am trying to retrieve data from oracle into PHP and I have successfully accomplished that, but the data appeared in question marks (??????), so I add the AMERICAN_AMERICA.AR8MSWIN1256 to NLS language in the registry for oracle and now the data appears as (ÓÇãÑ ÝíáíÈ ÚíÏ ÇáÚÏíáí). I tried encoding and all suggested character sets from IE and from the PHP code but had no results. I tried Windows-1256, UTF-8 & 16, I would appreciate some support for this issue
By the way anything else in the page that is not generated from the database and written in arabic appears in arabic OK with no problems so i have no problem with that, only with what is generated from the database.
windows-1256 generates (ÓÇãÑ ÝíáíÈ ÚíÏ ÇáÚÏíáí)
UTF-8 generates (����� � ����� )
Thank you
Post Reply