PHP漢字轉拼音程式碼分析

來源:互聯網
上載者:User
首先需要前台模版index.html

漢子轉拼音帶音標_PHP部落格                                         
 
  • 首 頁
  • 文章列表

教程:漢子轉拼音程式碼分析

內容: Powered by sucaihuo.com 本站皆為作者原創,轉載請註明原文連結:liqingbo.cn

當我們輸入所要轉換的漢字後,將資料提交到pinyin.php檔案進行轉換,在返回到index.html檔案中

完整代碼:

public function pinyin(){        if(IS_POST){            header("Content-Type:text/html;charset=utf-8");            include(APPLICATION."Common/ChinesePinyin.class.php");            $Pinyin = new ChinesePinyin();             $str = $_POST['str'];             if(strlen($str)<=0){                echo '請輸入要轉換的內容';                exit;            }            $pinyin1 = $Pinyin->TransformWithTone($str);            $pinyin2 = $Pinyin->TransformWithoutTone($str);            $pinyin3 = $Pinyin->TransformUcwordsOnlyChar($str);            $pinyin4 = $Pinyin->TransformUcwords($str);            echo '帶聲調的漢語拼音: '.$pinyin1.'';            echo '
'; echo '無聲調的漢語拼音: '.$pinyin2.''; echo '
'; echo '首字母只包括漢字: '.$pinyin3.''; echo '
'; echo '首字母和其他字元: '.$pinyin4.''; echo '
'; exit; } $this->display('pinyin'); }

以上例子為thinkphp架構下的

執行個體效果:漢子轉拼音帶音標

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.