maverick5x Posted May 2, 2008 Share Posted May 2, 2008 Hello, I am having problems developing an arabic website using PHP/MySQL and ajax. Arabic text in pages is displayed as is with no problems. but when data is posted from an html form the data are saved in the database in UTF-8 encoding. I though it was from the mysql collation thing and charsets but it wasn't. I discovered that when data is sent to the PHP script, it reads them as utf-8 strings although i did specify the charset in the ajax post request xmlHttp.onreadystatechange=AjaxStateChanged; xmlHttp.open("POST",url,true); xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=Windows-1256"); xmlHttp.send(postdata); I knew that by replacing html that should be displayed as a response to my page by the sql statement that contains the values posted and they appear as some wierd characters. So we can tell it's not the mysql, nor ajax(it shows correct encoding in "alert" before posting). I think i can say it's in the http connection. Is there a solution to this one? i cannot convert to utf-8 because i have a huge database with arabic (windows-1256) data on it. Hope someone has the answer best regards, Rakan Quote Link to comment Share on other sites More sharing options...
zohab Posted May 29, 2008 Share Posted May 29, 2008 try following for utf8 header("Content-Type: text/html; charset=utf8\n"); for Windows-1256 header("Content-Type: text/html; charset=Windows-1256\n"); with the help of above it will set charset to Windows-1256 for current page data display. use in the top of the page <?php header("Content-Type: text/html; charset=Windows-1256\n"); ?> Quote Link to comment Share on other sites More sharing options...
haku Posted May 30, 2008 Share Posted May 30, 2008 If your javascript is in an external file, you can also try setting a charset for that file (I have had similar problems working with Japanese): <script type="text/javascript" src="javascript/user_details.js" charset="EUC-JP"></script> note: replace 'EUC-JP' with the charset of your choice. That just happens to be the one I use. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.