0

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 "тыуиппюлкйчг ";
?>
Slava Vedenin
  • 58,326
  • 13
  • 40
  • 59
user3244721
  • 714
  • 2
  • 11
  • 29

6 Answers6

2

Put a header charset=utf-8 in the page where you want to display it.

<?
header('Content-Type: text/html;charset=utf-8');
?>
1
  1. Make sure the database charset/collation is UTF-8

  2. 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.

  3. 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.

  4. 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

Community
  • 1
  • 1
eL-Prova
  • 1,084
  • 11
  • 27
  • For russian or russian-english website utf8_general_ci collation is usually used. If languages with special latin characters are to be used (such as german), utf8_unicode_ci is needed. – Mikhail Batcer May 06 '14 at 08:05
  • I saved sucessfully in database...i can see there...But when i want to get it back it give me ????? please see my updated question – user3244721 May 06 '14 at 08:12
0

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/

Clément Andraud
  • 9,103
  • 25
  • 80
  • 158
0

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;
Kakitori
  • 901
  • 6
  • 16
  • 41
0

Please set mysql_set_charset('utf8'); Above Where you displaying the data.

Stephen
  • 69
  • 2
  • 10
0

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");
Mark Ormesher
  • 2,289
  • 3
  • 27
  • 35
Clarenceli
  • 31
  • 5