Tuesday, 30 September 2014

PHP output JSON Web Service charset UTF-8 get multi languange data like hindi,franch

set database filed collation in table.

if you add another langauge data like hindi,gujrati  first chanage strucute
change Collation as utt8_general_ci.



//$uid = isset($_GET['uid']) ? mysql_escape_string($_GET['uid']) : "";

$uid = 1;
mysql_query ("set character_set_results='utf8'");// set names mysql query
       $qur =  mysql_query("select name,address from gujrati_data where id ='$uid'");

       $result = array();
       while($r = mysql_fetch_array($qur)){
          // echo $r['name'];
           //echo $r['address'];
           $result[] = array("name" => $name,"email" => $address);
       $json = array("status" => 1, "info" => $result);
       $json =  array("status" => 0, "msg" => "User ID is Not Define");
    header('Content-Type: application/json; charset=utf-8'); // set this header in json
    //echo json_encode($json);
    echo (json_encode($json,JSON_UNESCAPED_UNICODE));

// add this JSON_UNESCAPED_UNICODE in json output


below i will show you what change in your query

Step 1)

Change database field Structure

open Table fileld Structure and change in collation set there utf8-general_ci

step 2)

set mysql_quey before fire query
mysql_query ("set character_set_results='utf8'"); set this

step 3)

header('Content-Type: application/json; charset=utf-8'); // set this header in json

If you want this in html then you can use <?php header ('Content-type: text/html; charset=utf-8'); ?> also you can use
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

in html use echo $r[‘name’]; it get in multi langage

step 4)

after end of json return json_encode your rensponse with JSON_UNESCAPED_UNICODE

like this
echo (json_encode($json,JSON_UNESCAPED_UNICODE));


Thank You For Comment