If we have to add another langauge data like franch,hindi,gujrati etc, we will have to change Collation as "utt8_general_ci".
Below are the detailed code and easy steps.
PHP code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | include_once ( "conif.php" ); // include database config file //$uid = isset($_GET['uid']) ? mysql_escape_string($_GET['uid']) : ""; $uid = 1; mysql_query ( "set character_set_results='utf8'" ); // set names mysql query if (! empty ( $uid )){ $qur = mysql_query( "select name,address from gujrati_data where id ='$uid'" ); $result = array (); while ( $r = mysql_fetch_array( $qur )){ extract( $r ); // echo $r['name']; //echo $r['address']; $result [] = array ( "name" => $name , "email" => $address ); } $json = array ( "status" => 1, "info" => $result ); } else { $json = array ( "status" => 0, "msg" => "User ID is Not Define" ); } header( 'Content-Type: application/json; charset=utf-8' ); // set this header in json @mysql_close( $conn ); //echo json_encode($json); echo (json_encode( $json ,JSON_UNESCAPED_UNICODE)); // add this JSON_UNESCAPED_UNICODE in json output |
Below are the steps show what changes we have to made in our query
Step 1:
Change database field Structure.
open Table fileld Structure and change in collation set there "utf8-general_ci". Below is screenshot
Step 2:
set mysql_quey before fire query
1 | mysql_query ( "set character_set_results='utf8'" ); |
Step 3:
1 | header( 'Content-Type: application/json; charset=utf-8' ); // set this header in json |
If we want this in html then we can use
1 | header ( 'Content-type: text/html; charset=utf-8' ); ?> |
also you can use
1 | < 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
1 | echo (json_encode( $json ,JSON_UNESCAPED_UNICODE)); |
Hope this post will helpful for you :)
No comments:
Post a Comment