user3244721
user3244721

Reputation: 754

Russian Language in PHP HTML

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

Answers (6)

Clarenceli
Clarenceli

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

Stephen
Stephen

Reputation: 79

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

Upvotes: 0

eL-Prova
eL-Prova

Reputation: 1094

  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

Upvotes: 1

Kakitori
Kakitori

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

user2189366
user2189366

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

Cl&#233;ment Andraud
Cl&#233;ment Andraud

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

Related Questions