Reputation: 754
I saved Russian Language in PHP & MySql. Here is sample characters тыуиппюлкйчг
I used these lines in PHP while saving
mysql_query("set character_set_server='utf8'");
mysql_query("set names 'utf8'");
I checked in Database it saved sucessfully..Now i want to display it to user in EDITOR,It return me ????????????
Here is my code how i am getting from table and display it
$.getJSON("getSingleRow.php?id="+id+"&type="+type, function(json){
$("#"+key).val(val);
});
And on getSingleRow.php i have this code
echo json_encode($russian);
Note: when i run getSingleRow.php directly,it also prints ????????????
UPDATED: First of all,It saved sucessfully in database,i can see there is in russian language.
I have two pages to get it.One page having editor,I have this line on top
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Also on top in php i have this line
header('Content-Type: text/html;charset=utf-8');
Other file is on server side from where i get it...getSingleRow.php
On top of this page i have
header('Content-Type: text/html;charset=utf-8');
and on end i have this code
echo json_encode($russian);
All answers given to this question has been applied already but no luck
EVEN simple this code is not working
<?php
header('Content-Type: text/html;charset=utf-8');
echo "тыуиппюлкйчг ";
?>
Upvotes: 0
Views: 2457
Reputation: 31
After using this code
$conn = mysqli_connect($dbhost, $dbuser, $dbpass);
you have to add this code for Russian language in MySQL.
mysqli_query($conn, "set names utf8");
Upvotes: 0
Reputation: 79
Please set mysql_set_charset('utf8');
Above Where you displaying the data.
Upvotes: 0
Reputation: 1094
Make sure the database charset/collation is UTF-8
On the page you insert these russian characters ( the form, textarea ), make sure the encoding is UTF-8, by setting Content-Type to text/html; charset=utf-8. Enter in russian text directly to the form input.
On the processing page that handles this form, which inserts it into the database, make sure to do SET NAMES utf8 so it's stored as UTF-8 before you insert the data, in a separate query beforehand.
When you render the content from the database in a view, make sure the Content-Type is text/html; charset=utf-8.
Make sure that the content-type is not windows-1251 or iso-8859-1/latin1. Make sure the database charset/collation is NOT ISO-8859-1/Latin1.
From: MySQL - Russian characters display incorectly
Upvotes: 1
Reputation: 913
Have you tried JSON_UNESCAPED_UNICODE parameter inside the json_encode() ?
json_encode($russian, JSON_UNESCAPED_UNICODE)
Just works in PHP 5.4.0
If your version is previous try this:
<?php
$str = 'russian - русский';
$str = json_encode($str);
$str = preg_replace_callback('/\\\\u([0-9a-f]{4})/i',
function ($matches) {
$sym = mb_convert_encoding(
pack('H*', $matches[1]),
'UTF-8',
'UTF-16'
);
return $sym;
},
$str
);
echo $str . PHP_EOL;
Upvotes: 0
Reputation:
Put a header charset=utf-8 in the page where you want to display it.
<?
header('Content-Type: text/html;charset=utf-8');
?>
Upvotes: 2
Reputation: 9269
The collation on the database must be set to cyrillic to accept the Russian characters. I ended up using the CYRILLIC_GENERAL_CI_AS collation set.
Check this link : http://www.davecheung.com/blogpost/converting-a-sql-server-2005-database-to-accept-russian-charactersmultilingual-characters/
Upvotes: 0