Page 1 of 1
problem with encode (charset) .. please help
Posted: Thu Aug 26, 2010 8:40 pm
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 ?
Re: problem with encode (charset) .. please help
Posted: Thu Aug 26, 2010 8:59 pm
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
Re: problem with encode (charset) .. please help
Posted: Fri Aug 27, 2010 6:28 am
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 !
Re: problem with encode (charset) .. please help
Posted: Fri Aug 27, 2010 8:51 am
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
Re: problem with encode (charset) .. please help
Posted: Fri Aug 27, 2010 10:01 am
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

Re: problem with encode (charset) .. please help
Posted: Fri Aug 27, 2010 10:04 am
by ScOrPi
by the way could u see this topic ?
viewtopic.php?f=1&t=120299
Re: problem with encode (charset) .. please help
Posted: Fri Aug 27, 2010 9:58 pm
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.
Re: problem with encode (charset) .. please help
Posted: Sat Aug 28, 2010 10:15 am
by ScOrPi
Thank you for ur help and useful notes ..
i appreciate ur help
Re: problem with encode (charset) .. please help
Posted: Sat Aug 28, 2010 11:58 am
by PHPHorizons
Sure thing

Re: problem with encode (charset) .. please help
Posted: Wed Oct 06, 2010 1:24 am
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