Dictionary-based high-quality Chinese-to-pinyin solution (PHP)-php Tutorial

Source: Internet
Author: User
Based on the Dictionary of Chinese Pinyin Conversion of high-quality solutions (PHP) based on the CC-CEDICT dictionary of Chinese pinyin conversion tools, more accurate Chinese pinyin conversion solution.

SAE service address: http://string2pinyin.sinaapp.com/doc.html

Use \ Overtrue \ Pinyin; echo Pinyin: trans ('Traveling with hope, better than arriving at the endpoint '); // d à I zhe x w wà ng q ù l ǔ xíng B ǐ d à o dázh ō ng di ǎ n gè ng m ě I h ǎ o // polyphonic words // Pinyin:: trans ('hangzhou'); // li Yuno ránpinyin: trans ('lai'); // lái le // Also Pinyin :: trans ('You'); // hái y ǒ uPinyin: trans ('Return'); // ji ā o huán // sh Pinyin :: trans (''); // shén mePinyin: trans ('assorted '); // shíj then n // then Pinyin :: trans ('stopped'); // bi à n d your ngPinyin: trans ('Cheap '); // pi á n yí // Peel Pinyin :: trans ('skinning'); // B branch o pípinyin: trans ('skinner'); // B branch píq branch // not Pinyin :: trans ('odds '); // Péi búshipinyin: trans ('ran the monk and couldn't run the miao '); // p ǎ o le héshà ng, p ǎ o B ù li ǎ o mi à o // drop Pinyin: trans ('cool-down '); // ji à ng w Jun nPinyin: trans ('surrender '); // tóu siáng // both Pinyin: trans ('capital '); // sh weight u d weight Pinyin: trans ('All Ages '); // d your u sh é n me ni á n d à I le // le Pinyin: trans ('Happy '); // ku à I l é Pinyin :: trans ('Music'); // y symbol n yu è // long Pinyin: trans ('dash'); // ch é ng zh symbol ngPinyin :: trans ('changjiang '); // cháng ji ā ng // difficult Pinyin: trans ('refugee'); // n à n mínpinyin :: trans ('sorted'); // nán gu Gou

Install
  • Install with Composer:

    composer require overtrue/pinyin:2.*

    Or add the following content to your project composer. json:

    { "require": { "overtrue/pinyin": "2.*" }}

  • Directly download the src/Pinyin. php file and introduce it to the project.

  • Use
     'Traveling with hope is better than arriving at the endpoint ', // 'Pinin' => 'd à I zhe x Jun wà ng q? l then xíng B then d à o dázh then ng di then n gè ng m branch I h branch O ', // 'letter '=> 'd z x w q l x B d z d g m H ',//); // load the custom supplemental dictionary $ appends = array ('leng '=> 're4',); Pinyin: appends ($ appends); echo Pinyin :: trans ('cool '); // rè

    Set
    Option Description
    Delimiter Delimiter, which is a space by default.
    Accent Output tone?
    Only_chinese Retain only the Chinese part of $ string
    Uppercase Specifies the upper case when the first letter is used. the default value is false.

    Global Settings: Pinyin: set ('delimiter ','-');

    Temporary settings: Pinyin: trans ($ word, $ settings)

    Example:

    Pinyin: set ('delimiter', '-'); // global echo Pinyin: trans ('Traveling with hope, better than arriving at the endpoint '); // d à I-zhe-x random-wà ng-q random-l random-xíng-B random-d à o-d á-zh random ng-di when n-gè ng-m then I-h then o $ setting = ['delimiter' => '-', 'accent' => false,]; echo Pinyin: trans ('Traveling with hope, better than arriving at the endpoint ', $ setting ); // The setting here is only temporary modification, not set globally // dai-zhe-xi-wang-qu-lu-xing-bi-dao-da-zhong-dian-geng-mei-hao

    Pinyin: set ('accent', false); echo Pinyin: trans ('travel with hope, better than arriving at the endpoint '); // dai zhe xi wang qu lu xing bi dao da zhong dian geng mei hao

    Use in Laravel

    The independent package is here: overtrue/laravel-pinyin

    Use

    The method is the same as the above:

    Use \ Overtrue \ Pinyin; //... $ pinyin = Pinyin: trans ("traveling with hope is better than arriving at the end ");

    ODO
    • Add and obtain the first letter;
    • Add a supplementary Dictionary;
    • Add a audio frequency table to improve the accuracy of multiple audio words in unmatched dictionaries;
    • Add the uppercase option for the first letter output;
    • Supports loading custom dictionary: Pinyin: appends ($ appends = array ());
    • Support Laravel 5 service provider. Overtrue/laravel-pinyin
    Https://github.com/overtrue/pinyin

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.