Reputation: 1
<?php
$unicodeChar = '\u0939';
echo json_decode('"'.$unicodeChar.'"');
?>
prints : ह
expected : ह
unicode '\u0939' decoding to original character using json.
Upvotes: 0
Views: 1738
Reputation: 15141
Set character encoding to UTF-8
for displaying Hindi
characters.
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:
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