I am currently designing a mobile application for Android. The text and content are in the Local Indic Language, Tamil. For Welcome, the equivalent of Tamil translation is: வணக்கம்
. Since Android cannot display Indic Text, I am converting it using a service called JavaScript String Escape.
我目前正在为Android设计移动应用程序。文本和内容采用当地印度语,泰米尔语。对于欢迎,相当于泰米尔语的翻译是:வணக்கம்。由于Android无法显示印度文字,因此我使用名为JavaScript String Escape的服务对其进行转换。
So this works in this way:
所以这可以这样工作:
-
Input:
வணக்கம்
- 输入:வணக்கம்
-
Output:
\u0BB5\u0BA3\u0B95\u0BCD\u0B95\u0BAE\u0BCD
- 输出:\ u0BB5 \ u0BA3 \ u0B95 \ u0BCD \ u0B95 \ u0BAE \ u0BCD
How can I make this using JavaScript or PHP as I have huge loads of text to be converted and made it into JSON. Sample JSON:
如何使用JavaScript或PHP来实现这一点,因为我需要转换大量文本并将其转换为JSON。示例JSON:
{
"title": "\u0BAE\u0BB0\u0BC1\u0BA4\u0BCD\u0BA4\u0BC1\u0BB5\u0BB0\u0BBF\u0BA9\u0BCD \u0BAA\u0BC6\u0BAF\u0BB0\u0BCD #1",
"image": "http://www.exceptnothing.com/doctors/doc11.png",
"rating": "\u2713 \u0B87\u0BAA\u0BCD\u0BAA\u0BC7\u0BBE\u0BA4\u0BC1 \u0BAA\u0BBE\u0BB0\u0BCD\u0B95\u0BCD\u0B95\u0BB2\u0BBE\u0BAE\u0BCD",
"rating2": "",
"releaseYear": "\u0BA8\u0BBE\u0BB3\u0BCD \u0BAE\u0BC1\u0BB4\u0BC1\u0BB5\u0BA4\u0BC1\u0BAE\u0BCD \u0BAA\u0BBE\u0BB0\u0BCD\u0B95\u0BCD\u0B95\u0BB2\u0BBE\u0BAE\u0BCD",
"genre": ["\u25B6 \u0B87\u0BA4\u0BAF \u0BA8\u0BBF\u0BAA\u0BC1\u0BA3\u0BB0\u0BCD"]
}
I also would like to know how to decode the above JSON and show it as வணக்கம்
. Thanks in advance.
我也想知道如何解码上面的JSON并将其显示为வணக்கம்。提前致谢。
1 个解决方案
#1
4
What you are looking for is escape()
in JavaScript and json_encode()
in PHP. Open up your console and type the following:
您正在寻找的是JavaScript中的escape()和PHP中的json_encode()。打开控制台并键入以下内容:
escape("வணக்கம்")
And you will get the following back:
你会得到以下回复:
"%u0BB5%u0BA3%u0B95%u0BCD%u0B95%u0BAE%u0BCD"
So the first one is solved. To get back the original வணக்கம்
from the above one, use unescape()
:
所以第一个问题就解决了。要从上面的内容中恢复原始的வணக்கம்,请使用unescape():
unescape("%u0BB5%u0BA3%u0B95%u0BCD%u0B95%u0BAE%u0BCD");
Note: One thing to be noted is, both
escape()
andunescape()
are deprecated. So you need to useencodeURIComponent
anddecodeURIComponent
注意:需要注意的一点是,不推荐使用escape()和unescape()。所以你需要使用encodeURIComponent和decodeURIComponent
Preview
预习
Update for Server Side
服务器端更新
For encoding and decoding into JSON, it is better for you to use the PHP's built-in function. The same escape()
can also be used in PHP as json_encode()
, they both give the same result.
对于JSON的编码和解码,最好使用PHP的内置函数。同样的escape()也可以在PHP中用作json_encode(),它们都给出相同的结果。
json_encode("வணக்கம்");
=> "%u0BB5%u0BA3%u0B95%u0BCD%u0B95%u0BAE%u0BCD"
Also, see JavaScript: Escaping Special Characters for more information. Hope this helps. :)
另请参阅JavaScript:转义特殊字符以获取更多信息。希望这可以帮助。 :)
#1
4
What you are looking for is escape()
in JavaScript and json_encode()
in PHP. Open up your console and type the following:
您正在寻找的是JavaScript中的escape()和PHP中的json_encode()。打开控制台并键入以下内容:
escape("வணக்கம்")
And you will get the following back:
你会得到以下回复:
"%u0BB5%u0BA3%u0B95%u0BCD%u0B95%u0BAE%u0BCD"
So the first one is solved. To get back the original வணக்கம்
from the above one, use unescape()
:
所以第一个问题就解决了。要从上面的内容中恢复原始的வணக்கம்,请使用unescape():
unescape("%u0BB5%u0BA3%u0B95%u0BCD%u0B95%u0BAE%u0BCD");
Note: One thing to be noted is, both
escape()
andunescape()
are deprecated. So you need to useencodeURIComponent
anddecodeURIComponent
注意:需要注意的一点是,不推荐使用escape()和unescape()。所以你需要使用encodeURIComponent和decodeURIComponent
Preview
预习
Update for Server Side
服务器端更新
For encoding and decoding into JSON, it is better for you to use the PHP's built-in function. The same escape()
can also be used in PHP as json_encode()
, they both give the same result.
对于JSON的编码和解码,最好使用PHP的内置函数。同样的escape()也可以在PHP中用作json_encode(),它们都给出相同的结果。
json_encode("வணக்கம்");
=> "%u0BB5%u0BA3%u0B95%u0BCD%u0B95%u0BAE%u0BCD"
Also, see JavaScript: Escaping Special Characters for more information. Hope this helps. :)
另请参阅JavaScript:转义特殊字符以获取更多信息。希望这可以帮助。 :)