Jibin
Jibin

Reputation: 464

json_encode return false when the page contain Arabic data

I am using ajax function to fetch data from database and replace a div.The data is fetched and the page is created from the controller, but when I use PHP json_encode it return false.

Then I used the below code:

    $data=utf8_encode($this->load->view('site' . $_SESSION['language'] . '/property_data', $data, TRUE));

    json_encode($data);

I am getting the out put like this after the encoding,

enter image description here

Here the encoding works fine,but when I use JavaScript decode, it's not working (the Arabic content is not displaying properly).

Upvotes: 0

Views: 181

Answers (1)

stan chacon
stan chacon

Reputation: 768

First you need set the charset of your DB with utf-8, if you are using mysql use :

mysql_query("SET NAMES 'utf8'");

And then in your json_encode use:

json_encode($result, JSON_UNESCAPED_UNICODE);

Hope it helps

Upvotes: 1

Related Questions