How to solve this PHP Ajax Arabic Characters Encoding issue?
I develop a web site using PHP and I connect to Sybase database using PHP ODBC functions.
There is a web page related to the Customers in order to input their data to confirm a service provided in the web site.
I use Ajax to get the Customer Data from the database in case that the customer enters an ID that exists in the database as I do the query to get his data like Number,Name,Mobile,Email and I concatenate these data so that I make it one string using a seperator character like * then I divide the string using substr() function in the Javascript file when Ajax is operated and the result is returned. I assign the values returned to the text boxes displayed in the web page.
This scenario goes perfect even some data is missed in the customer record being sent.
My problem is that the database has two languages for the text stored in it : English and Arabic. It goes perfect with English but when the customer data is Arabic, the Javascript开发者_运维知识库 acts as there is no data at all or it encodes it to strange characters that could not be read.
How I can solve that as I checked all matters related to the langauage and character encoding and using UTF-8 and Windows-1256 and also using the encoding conversion functions in PHP and Javascript Files and making sure of the file encoding itself.
Generally I use Windows-1256 to display the Arabic well in my php web pages as if I use UTF-8 the Arabic dynamic data coming from the database could not be displayed well but the Arabic static data written directly in the web page are ok.
Any help is appreciated and thanks in advance .....
Well,
First: Add by the beginning of HTML page
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
second: if you are using AJAX encode data using encodeURIComponent
Third: First line of your PHP page should be
header('Content-Type: text/html; charset=utf-8');
and decode the data sent to PHP using urldecode
also,if you are using oracle as DB use, the following connection string: $connect=oci_connect($UserName,$Password,$db_name,'AL32UTF8')
Regards,
精彩评论