Each Chinese Character has a tone and can be expressed using alphabet letters (namely the Pinyin), for example:
我, prounced as wo (the third tone).
and 你好, the famous way of saying Hello in Chinese sounds like: Ni Hao
both Pinyin are the third tone.
In this project, I have developed a PHP - API which allows you to quickly convert a set of Chinese characters to its Pinyin expressions. This API is also live at:
https://helloacm.com/api/pinyin/?cached&s=你好
It will return JSON:
{"result":["ni","hao"]}
You can also pass t=1
parameter to get its tones:
https://helloacm.com/api/pinyin/?cached&s=你好&t=1
which will return:
{"result":["ni3","hao3"]}
The Chinese tool page is: https://justyy.com/archives/3450
The github source is: https://github.com/DoctorLai/ChineseToPinYin
PHP API
The PHP API source code:
<?php
// https://justyy.com/archives/3450
$s = '';
if (isset($_GET['s'])) {
$s = $_GET['s'];
} else {
if (isset($_POST['s'])) {
$s = $_POST['s'];
}
}
$t = false;
if (isset($_GET['t'])) {
$t = (bool)($_GET['t']);
} else {
if (isset($_POST['t'])) {
$t = (bool)($_POST['t']);
}
}
$data = array();
$db = 'pinyin.txt';
if (is_file($db)) {
$result = array();
$array = preg_split('/$\R?^/m', trim(file_get_contents($db)));
$hash = array();
foreach ($array as $v) {
$v = trim($v);
$c = substr($v, 0, 3);
$hash[$c] = substr($v, 3);
}
$slen = mb_strlen($s,'UTF-8');
for ($i = 0; $i < $slen; $i ++) {
$c = mb_substr($s, $i, 1);
$tmp = $hash[$c];
if (!$t) {
$tmp = str_replace(array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'), '', $tmp);
}
if ($tmp) {
$result[] = $tmp;
} else {
$result[] = $c;
}
}
$data['result'] = $result;
} else {
$data['error'] = 'cannot read data';
}
header("Access-Control-Allow-Origin: *");
header('Content-Type: application/json');
die(json_encode($data));
Proof of Work
My github ID is doctorlai
and on the profile page, it has my steemit shown.
Posted on Utopian.io - Rewarding Open Source Contributors
Congratulations @justyy! You have completed some achievement on Steemit and have been rewarded with new badge(s) :
Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here
If you no longer want to receive notifications, reply to this comment with the word
STOP
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thank you, 谢谢您。
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
my pleasure, önemli değil. :)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hey @justyy I am @utopian-io. I have just upvoted you!
Achievements
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
I like your post, I think simple and good. Please help me, I just joined in steemit ..
https://steemit.com/introduction/@annisaulya/hi-guys-i-am-annisa-i-come-from-indonesia-and-i-m-newbie-in-steemit-b7e2c048bb828
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit