0
mysqli_set_charset($conn, "utf8");
$stmt= $conn->prepare("SELECT id, title FROM ****************");
$stmt->execute();
$stmt->bind_result($id,$title);
$arr = array();
while($stmt->fetch()){
    $study= (object)array();
    $study->id = $id;
    $study->title=$title;
    array_push($arr,$study);
}
echo json_encode($arr);

Here is the result of the above code

enter image description here

Questions

  1. How can I achieve full unicode support in my json data?

  2. How can I remove the html tags while sending the data to mobile apps?

What I am trying to accomplish is: This is a web API for my Android app in react native, I am having problem with unicode support. The main thing is when I paste the code on google search then it shows converted text, which means I am missing something here.

And when I use print_r[] to print the array the result is fine?

S.I.
  • 3,250
  • 12
  • 48
  • 77
Ujjwal Nepal
  • 546
  • 5
  • 13
  • How is the content saved in the database? Are you doing any encoding at that point? How does the data look in the database, if you're looking at it with a tool like MySQL Workbench? – M. Eriksson Nov 14 '16 at 06:52
  • To strip HTML tags: http://php.net/manual/en/function.strip-tags.php – M. Eriksson Nov 14 '16 at 06:53
  • This is the data fetched from database.This is the problem I was mentioning, when I use Print_r this data appears fine in the browser but not when I encode with json. I am looking data data in database with phpmyadmin.

    जिसस क्राइष्टको जन्म कहीले भएको हो ?

    – Ujjwal Nepal Nov 14 '16 at 07:01
  • Yes, we got that. Again: *How is the content saved in the database? Are you doing any encoding at that point?* – M. Eriksson Nov 14 '16 at 07:02
  • Were those data in unicode when added to the database? – Kishan Kumar Nov 14 '16 at 07:12
  • Thanks for the response, while writing to database there is no encoding. – Ujjwal Nepal Nov 14 '16 at 07:20
  • Since you are saving the content to the database without any encoding, the real question is, how do you encode the contents while serving it. Try using this PHP API (http://php.net/manual/en/function.utf8-encode.php), see if it works. – Sajib Acharya Nov 14 '16 at 08:57

2 Answers2

0

क is an "htmlentity". \u092e is "escaped unicode". Neither is generated by MySQL.

Htmlentities come from PHP and other sources. See the function by that name.

The \u.... may have come from not having the second argument in

$t = json_encode($s, JSON_UNESCAPED_UNICODE);
Rick James
  • 135,179
  • 13
  • 127
  • 222
0

I think finally I figured out what was the missing piece of the puzzle.

As @Ricky said those were the html entities, and with html_entity_decode the problem was solved. Thanks for the response

Ujjwal Nepal
  • 546
  • 5
  • 13
  • Instead of posting your own answer and accepting it, you should accept the answer of @Rick James, who took the pain to solve the problem for you. – Sajib Acharya Nov 21 '16 at 12:56
  • sorry to say, But I figured the answer myself, I was just sharing the answer so that anyone with the same problem to help themselves. Cheers – Ujjwal Nepal Nov 22 '16 at 14:10