0

How to use Tamil character in JSON php

<?php

    /* Author : Girija S
       Date   : 4/21/2011
       Description: To Check the Special Chars when we pass in the json server 
    */

    $text = "தமிழ் அகராதி With the exception <br>of HTML 2.0's &quot;, &amp;, &lt;, and &gt;, these entities are &#039;all&#039; <br>new<br/> in HTML 4.0 and may not be supported by old browsers. Support in recent browsers is good.The following table gives the character entity <p>reference, decimal character reference, and hexadecimal character reference for markup-significant</p> and internationalization characters\n, as well as the rendering of each in your browser. Glyphs of the characters are available at the Unicode Consortium.<p>This is some text in a paragraph.</p>";

    $text =  json_encode(utf8_encode($text));
    echo $text;
    $text =  json_decode($text);
    echo $text;
?>
Arulkumar
  • 12,966
  • 14
  • 47
  • 68
Thiyagu
  • 1
  • 3
  • Please specify your problem. – Naresh Nov 26 '14 at 05:36
  • I think you should not have the "utf8_encode" there... just remove it... json_encode will convert your Tamil chars to an escaped presentation, but should convert it back again on the json_decode! – goddva Nov 26 '14 at 05:53
  • I want English and tamil characters in same string 'தமிழ் அகராதி With the exception'. I want to display this string using php. Also use this string in insert,select, compare in query. But display or insert in the string output only ????? ?????? With the exception .. How to solve it – Thiyagu Nov 26 '14 at 06:52
  • http://stackoverflow.com/a/10924295/337128 – Thalaivar Apr 19 '16 at 12:11

2 Answers2

1

"meta http-equiv="Content-Type" content="text/html; charset=UTF-8""
use this in header it will solve the problem..
if you want to store in a data base you should yous
"mysql_query ("set character_set_results='utf8'"); "
before query..
I did like that and got success for my financial tamil application

-2
<?php
//Try it ... working script.. add MIME type and Font characterset in header
header('Content-type="application/json"');
header('charset="utf-8"');
$text = "தமிழ் அகராதி With the exception <br>of HTML 2.0's &amp;quot;, &amp;amp;, &amp;lt;, and &amp;gt;, these entities are &amp;#039;all&amp;#039; <br>new<br/> in HTML 4.0 and may not be supported by old browsers. Support in recent browsers is good.The following table gives the character entity <p>reference, decimal character reference, and hexadecimal character reference for markup-significant</p> and internationalization characters\n, as well as the rendering of each in your browser. Glyphs of the characters are available at the Unicode Consortium.<p>This is some text in a paragraph.</p>";
echo $text = json_encode($text);
echo '<br/><br/><br/>******************************************************************************<br/><br/>';

echo $text = json_decode($text, JSON_PRETTY_PRINT | JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE);
?>
Kavin D
  • 1
  • 6