longhongjun / pinyin

Chinese to pinyin translator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pinyin

Chinese to pinyin translator based on CC-CEDICT.

PHP extension is in progress

Install

  1. installing via Composer:

    Next, update your project's composer.json file to include Pinyin:

    {
        "require": {
            "overtrue/pinyin": "~1.0"
        }
    }
  2. download source file src/Overtrue/Pinyin.php and include it.

Usage

<?php
use \Overtrue\Pinyin;

echo Pinyin::trans('带着希望去旅行,比到达终点更美好');

// dài zhe xī wàng qù lǔ xíng bǐ dào dá zhōng diǎn gèng měi hǎo 

Setting

  • delimiter Separator between each pinyin, default is a space ' '.
  • accent Whether the output tone.

Pinyin::set($setting); or Pinyin::trans($word, $setting)

example:

<?php
use \Overtrue\Pinyin;

$setting = [
			'delimiter' => '-',
		   ];
Pinyin::set($setting);
echo Pinyin::trans('带着希望去旅行,比到达终点更美好');

// dài-zhe-xī-wàng-qù-lǔ-xíng-bǐ-dào-dá-zhōng-diǎn-gèng-měi-hǎo
<?php

use \Overtrue\Pinyin;

$setting = [
			'delimiter' => '-',
			'accent' => false,
		   ];

echo Pinyin::trans('带着希望去旅行,比到达终点更美好', $setting);

// dai-zhe-xi-wang-qu-lu-xing-bi-dao-da-zhong-dian-geng-mei-hao
<?php

use \Overtrue\Pinyin;

$setting = [
			'accent' => false,
		   ];
Pinyin::set($setting);
echo Pinyin::trans('带着希望去旅行,比到达终点更美好');

// dai zhe xi wang qu lu xing bi dao da zhong dian geng mei hao

License

MIT

About

Chinese to pinyin translator

License:MIT License