php中文转拼音

使用环境

thinkphp3.2.3 基于composer安装

使用过程

tip: “overtrue/pinyin”: “~3.0” 主要添加了这段

{
    "name": "topthink/thinkphp",
    "description": "the ThinkPHP Framework",
    "type": "framework",
    "keywords": ["framework","thinkphp","ORM"],
    "homepage": "http://thinkphp.cn/",
    "license": "Apache2",
    "authors": [
        {
            "name": "liu21st",
            "email": "liu21st@gmail.com"
        }
    ],
    "require": {
        "php": ">=5.3.0",
        "filp/whoops": "^2.1",
        "overtrue/pinyin": "~3.0"
    },
    "minimum-stability": "dev"
}

执行命令: composer update

thinkphp控制器中使用

<?php
namespace Admin\Controller;
require $_SERVER['DOCUMENT_ROOT'].__ROOT__.'/vendor/autoload.php';
class xxx{
$pinyin = new \Overtrue\Pinyin\Pinyin;//中文转拼音
$pinyin->convert('我是中文'); //取拼音 
$pinyin->abbr('我是中文'); //取首字母
}

 

中文转拼音 、 thinkphp3.2.3使用composer实例

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注