/**
  * Register the provider.
  *
  * @return void
  */
 public function register()
 {
     Pinyin::settings(config('pinyin', []));
     $this->app->singleton('pinyin', function ($app) {
         return Pinyin::getInstance();
     });
 }
Пример #2
0
 /**
  * Get the fist pinyin and letters of given string.
  *
  * @param  string $string
  * @param  array  $setting
  *
  * @return string
  */
 function pinyin_and_letter($string, $setting = [])
 {
     return Pinyin::parse($string, $setting);
 }
Пример #3
0
 public static function getPinyinFirst($word)
 {
     return BasePinyin::letter($word);
 }
Пример #4
0
 public static function getPinyinFirst($word)
 {
     BasePinyin::set('accent', false);
     BasePinyin::set('delimiter', '');
     return BasePinyin::letter($word);
 }
Пример #5
0
include "./src/Pinyin/Pinyin.php";
use Overtrue\Pinyin\Pinyin;
$filepath = dirname(__DIR__) . '/dict.php';
// echo __DIR__ . "\n";
// echo $filepath . "\n";
$dict = json_decode(file_get_contents($filepath), true);
$result = '';
foreach ($dict as $word => $pinyin) {
    if (mb_strlen($word, 'utf-8') > 1 && 3 == strlen($word) / mb_strlen($word, 'utf-8')) {
        // 有些短语是`一分耕耘,一分收获`这种类型,处理一下
        if (strpos($word, ',') !== false) {
            $pinyin = Pinyin::trans($word);
            $words = explode(',', $word);
            $pinyins = explode(',', $pinyin);
            for ($i = 0; $i < count($words); ++$i) {
                $w = $words[$i];
                $p = trim($pinyins[$i]);
                $p = str_replace(' ', ',', $p);
                $result = $result . $w . '=' . $p . "\n";
            }
        } else {
            $pinyin = str_replace(' ', ',', Pinyin::trans($word));
            $result = $result . $word . '=' . $pinyin . "\n";
        }
    }
}
echo "convert ... \n";
$fh = fopen('./phrase.db', "w");
fwrite($fh, $result);
fclose($fh);
Пример #6
0
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     $config = Config::get('pinyin');
     Pinyin::settings($config);
 }
Пример #7
0
<?php

namespace test;

require_once __DIR__ . "/src/Pinyin/Pinyin.php";
use Overtrue\Pinyin\Pinyin;
echo Pinyin::trans("你好");
echo "\n";
echo Pinyin::trans("爱屋及乌");
echo "\n";