jfeu1204
jfeu1204

Reputation: 1

PHP: Change charset encoding for Hindi

<?php 
$unicodeChar = '\u0939';
echo json_decode('"'.$unicodeChar.'"');
?>

prints : ह

expected : ह

unicode '\u0939' decoding to original character using json.

Upvotes: 0

Views: 1738

Answers (1)

Sahil Gulati
Sahil Gulati

Reputation: 15141

Set character encoding to UTF-8 for displaying Hindi characters.

Try this code snippet here

Here we are initiating a header which will set charset for displaying the content in hindi charset.

<?php
ini_set('display_errors', 1);
header('Content-type: text/plain; charset=UTF-8');
$unicodeChar = '\u0939';
echo json_decode('"'.$unicodeChar.'"');

Solution 2:

Try this code snippet here

Here we are setting default charset to UTF-8 using ini_set.

<?php
ini_set('display_errors', 1);
ini_set('default_charset', 'utf-8');

$unicodeChar = '\u0939';
echo json_decode('"'.$unicodeChar.'"');

Upvotes: 1

Related Questions