/** * Pinyin * @return Pinyin */ static function getInstance() { if (null == self::$_instance) { self::$_instance = new self(); } return self::$_instance; }
public function xjhy_3() { // 获取部门 人员 include 'User.php'; $user = new User(); session_start(); if (!isset($_SESSION['access_token'])) { $access_token = $user->GetAccessToken(); } else { if ($_SESSION['access_token']['time'] + 3600 < time()) { $access_token = $user->GetAccessToken(); } else { $access_token = $_SESSION['access_token']['access_token']; } } $departments = $user->GetUserDepartment($access_token); $data['departments'] = $departments; $data['users'] = $user->GetUserListByGroupId(2, $access_token); //按字母排序 include "/pinyin/src/Pinyin/Pinyin.php"; foreach ($data['users']['userlist'] as $key => $value) { $data['users']['userlist'][$key]['letter'] = substr(Pinyin::letter($value['name'], array('uppercase' => true)), 0, 1); } $ages = array(); foreach ($data['users']['userlist'] as $user) { $ages[] = $user['letter']; } array_multisort($ages, SORT_ASC, $data['users']['userlist']); $this->load->view('xjhy_3', $data); }
public static function &instance() { if (null === self::$instance) { self::$instance = new self(); } return self::$instance; }
function filename() { foreach ($_FILES as $file) { $name = explode('.', $file['name']); $ext = end($name); $name = $name[0]; } $pinyin = new Pinyin(); $pattern = '/[^\\x{4e00}-\\x{9fa5}\\d\\w]+/u'; $name = preg_replace($pattern, '', $name); $name = substr($pinyin->output($name, true), 0, 80); if (file_exists(__ROOTDIR__ . '/upload/' . date('Y-m') . '/' . date('d') . '/' . $name . '.' . $ext)) { $rand = '-' . substr(cp_uniqid(), -5); } return $name . $rand; }
public static function getInstance() { if (!Pinyin) { self::$instance = new Pinyin(); } return self::$instance; }
public function actionUpdate() { $lid = Yii::app()->request->getParam('lid'); //echo 'ddd'; $model = ProductSet::model()->find('lid=:lid and dpid=:dpid', array(':lid' => $lid, ':dpid' => $this->companyId)); Until::isUpdateValid(array($lid), $this->companyId, $this); //0,表示企业任何时候都在云端更新。 if (Yii::app()->request->isPostRequest) { $model->attributes = Yii::app()->request->getPost('ProductSet'); $py = new Pinyin(); $model->simple_code = $py->py($model->set_name); $model->update_at = date('Y-m-d H:i:s', time()); //var_dump($model->attributes);var_dump(Yii::app()->request->getPost('ProductSet'));exit; if ($model->save()) { Yii::app()->user->setFlash('success', yii::t('app', '修改成功')); $this->redirect(array('productSet/index', 'companyId' => $this->companyId)); } } $this->render('update', array('model' => $model)); }
public function actionUpdate() { $id = Yii::app()->request->getParam('id'); $model = Product::model()->find('lid=:productId and dpid=:dpid', array(':productId' => $id, ':dpid' => $this->companyId)); $model->dpid = $this->companyId; Until::isUpdateValid(array($id), $this->companyId, $this); //0,表示企业任何时候都在云端更新。 if (Yii::app()->request->isPostRequest) { $model->attributes = Yii::app()->request->getPost('Product'); $py = new Pinyin(); $model->simple_code = $py->py($model->product_name); $model->update_at = date('Y-m-d H:i:s', time()); if ($model->save()) { Yii::app()->user->setFlash('success', yii::t('app', '修改成功!')); $this->redirect(array('product/index', 'companyId' => $this->companyId)); } } $categories = $this->getCategoryList(); //$departments = $this->getDepartments(); $this->render('update', array('model' => $model, 'categories' => $categories)); }
/** * 汉字拼音转换程序(支持多音字) * * @param string $keyword * @return array */ public static function getPinyin($keyword, $type = null) { // 变量定义 $hz = PyDict::$hanzi; $result = ""; // 转换成utf-8编码数组 $utf8_arr = Pinyin::strSplitPhp5Utf8($keyword); switch ($type) { case 1: // 获取每个汉字的首字母 foreach ($utf8_arr as $char) { if (isset($hz[$char])) { $result .= substr($hz[$char][0], 0, 1); } else { $result .= $char; } } $result = array($result); break; case 2: // 只获取第一个汉字的首字母,非汉字统一为# foreach ($utf8_arr as $char) { if (isset($hz[$char])) { foreach ($hz[$char] as $pinyin) { $result[] = substr($pinyin, 0, 1); } } else { $value = ord($char); if ($value >= 65 && $value <= 89 || $value >= 97 && $value <= 122) { $result = strtolower($char); } else { $result = '#'; } $result = array($result); } break; } break; default: // 汉字转换成拼音 foreach ($utf8_arr as $char) { if (isset($hz[$char])) { $result .= $hz[$char][0]; } else { $result .= $char; } } $result = array($result); break; } return $result; }
/** * 汉字转拼音 * @param $string * @param $encoding */ private static function chineseToPinyin($string, $encoding) { $words = self::mbStringToArray(mb_convert_encoding($string, 'utf-8', $encoding)); self::$string = $string; self::$encoding = $encoding; self::$pinyin = ''; self::$short_pinyin = ''; foreach ($words as $v) { if (isset(self::$dic[$v])) { $tmp = self::$dic[$v]; } else { $tmp = $v; } self::$pinyin .= $tmp; self::$short_pinyin .= mb_substr($tmp, 0, 1, $encoding); } }
/** * 汉字转拼音 * @param string $srt * @return Ambigous <string, boolean, unknown> */ function get_pinyin($srt = '') { $py = new Pinyin(); return $py->output($srt); // 输出 }
/** * 截取一段话首字母 * * @param string $string 截取的字符串 * @param string $encode 编码,默认 utf-8 * @param string $unknow 不知道的字符返回什么,默认返回第一个字 * @return string * @author Seven Du <*****@*****.**> **/ function getShortPinyin($string, $encode = 'utf-8', $unknow = null) { $pre = $unknow !== null ? $unknow : mb_substr($string, 0, 1, $encode); $string = Pinyin::getShortPinyin($string, $encode); $string = mb_substr($string, 0, 1); $string = strtoupper($string); /* 转为大写 */ if (!in_array($string, explode(',', 'Q,W,E,R,T,Y,U,I,O,P,A,S,D,F,G,H,J,K,L,M,N,B,V,C,X,Z'))) { $string = $pre; } return $string; }
$id = intval($_GET['id']); $TEMPLATE['data'] = $data = $task->get($id); if ($data['uid'] != Passport::GetLoginUid()) { echo '没有权限!'; exit; } switch ($_POST['action']) { case '修改': $TEMPLATE['data'] = array_merge($data, $_POST); if (!validate()) { } else { $tableInfo = array('title' => $_POST['title'], 'content' => $_POST['content']); if ($data['cat'] == 'weibo') { if ($_FILES['image']['tmp_name']) { @mkdir(UPLOAD_PATH, 0777, true); $save_file = $upload_file = UPLOAD_PATH . microtime(true) . '_' . Pinyin::get($_FILES['image']['name']); move_uploaded_file($_FILES['image']['tmp_name'], $save_file); $tableInfo['pic'] = $save_file; } } if ($_POST['time'] == 'on') { $tableInfo['status'] = Task::TASK; $tableInfo['send_time'] = strtotime($_POST['send_time']); } $task->update($tableInfo, array('id' => $id)); $item = $task->get($id); $TEMPLATE['report']['edit'] = array('status' => true, 'msg' => '修改成功,<a href="' . $_POST['return_url'] . '"><返回</a>(<span id="countdown">5</span>) <script> var countd = 5; var tt = setInterval(function(){ if (--countd == 0) {
public function __construct() { parent::__construct(); }
<?php $user = get_current_user(); $obj = new Pinyin(); $obj->loadDict("/home/{$user}/local/pinyin/dict/dict.dat", Pinyin::TY_DICT); $obj->loadDict("/home/{$user}/local/pinyin/dict/dyz.dat", Pinyin::DYZ_DICT); $obj->loadDict("/home/{$user}/local/pinyin/dict/duoyong.dat", Pinyin::DY_DICT); $obj->loadDict("/home/{$user}/local/pinyin/dict/dz_pro.dat", Pinyin::BME_DICT); //$obj->loadDict("/home/work/local/pinyin/dict/dict_tone.dat", Pinyin::TY_TONE_DICT); //$obj->loadDict("/home/work/local/pinyin/dict/dyz_tone.dat", Pinyin::DYZ_TONE_DICT); $str = "大家会计60好80"; $str = preg_replace('/(\\w+)/', '\'$1\'', $str); $str = trim($str, "'"); var_dump($str); preg_match_all('/([\\x{4e00}-\\x{9fa5}]+)/iu', $str, $matches); $gbkItems = array(); foreach ($matches[1] as $item) { $gbkItems[] = iconv("UTF-8", "GBK", $item); } $pinyinItems = $obj->multiConvert($gbkItems); var_dump($matches[1], $gbkItems, $pinyinItems); var_dump($result = str_replace($matches[1], $pinyinItems, $str)); exit; var_dump($obj->convert(iconv("UTF-8", "GBK", "重庆重量"))); var_dump($obj->multiConvert(array(iconv("UTF-8", "GBK", "重庆南京市长江大桥财务会议会计")))); var_dump($obj->multiConvert(array(iconv("UTF-8", "GBK", "重庆"), iconv("UTF-8", "GBK", "重量")))); var_dump($obj->exactConvert(iconv("UTF-8", "GBK", "中华人民共和国"))); function getPinyin($chars) { } // $reult = $obj->generateDict("/home/work/local/pinyin/dict/dict.txt", "/home/work/tmp/dict.dat");
/** * keywords输入中文 * @param type $keywords * @return * keywords:中国 return:zhongguo * keywords:中国 中国 return:zhongguo zhongguo */ public static function getEnKeywords($keywords) { $enKeywords = ''; if (strpos($keywords, ' ') && ($keywords = explode(' ', $keywords))) { foreach ($keywords as $value) { if ($value) { $enKeywords .= Pinyin::get($value) . ' '; } } $enKeywords = rtrim($enKeywords, ' '); } else { $enKeywords = Pinyin::get($keywords); } return $enKeywords; }
/** * 中文字符转拼音 * * @param string $str * @param string $utf8 */ function string_to_pinyin($str, $utf8 = true) { static $obj = null; if ($obj === null) { $obj = new Pinyin(); } return $obj->output($str, $utf8); }
<?php require_once "Pinyin.class.php"; $pinyin = new Pinyin(); $str = $_POST['str']; echo $pinyin->strtopin($str, 1);
/** * 获取城市名称 */ public function get_city($ip) { $localinfo = ''; $address = $this->get($ip); if (strpos($address, '省') !== false && strpos($address, '市') !== false) { $address = explode('省', $address); $address = $address[1]; } $address = str_replace('市', '', $address); $localinfo['city'] = trim($address); $name = CHARSET == 'gbk' ? $localinfo['city'] : iconv('utf-8', 'gbk', $localinfo['city']); $name = str_replace('市', '', $name); $letters = Pinyin::instance()->output($name, false); $localinfo['pinyin'] = strtolower($letters); return $localinfo; }
/** * 新 注册接口 * * @request int $phone 用户注册手机号码 * @request int $code 用户注册手机验证码 * @request string $username 用户名 * @request string $password 用户密码 * @request string $intro User intro. * @request int $sex 用户性别,1:男,2:女,default:1 * @request string $location 格式化的地区地址,format:“省 市 区/县” * @request int $province 地区-县/直辖市 areaId * @request int $city 地区-市/直辖市区县 areaID * @request int $area 地区-区/县/直辖市村 * @request string $avatarUrl 用户头像URL * @request int $avatarW 用户头像宽度 * @request int $avatarH 用户头像宽度 * @return array * @author Seven Du <*****@*****.**> **/ public function signIn() { $phone = floatval($this->data['phone']); // 手机号码 $code = intval($this->data['code']); // 验证码 $username = t($this->data['username']); // 用户名 $password = $this->data['password']; // 密码 $intro = $this->data['intro'] ? formatEmoji(true, t($this->data['intro'])) : ''; // 用户简介 $sex = intval($this->data['sex']); in_array($sex, array(1, 2)) or $sex = 1; // 默认 男 1.男,2女 $location = t($this->data['location']); // 地区文字 $province = intval($this->data['province']); // 地区 - 省 $city = intval($this->data['city']); // 地区 - 市 $area = intval($this->data['area']); // 地区 - 区/县 $avatarUrl = t($this->data['avatarUrl']); // 用户头像URL $avatarW = intval($this->data['avatarW']); // 用户头像宽度 $avatarH = intval($this->data['avatarH']); // 用户头像高度 $register = model('Register'); $config = model('Xdata')->get('admin_Config:register'); // 配置 /* 判断用户手机号码可用性 */ if (!$register->isValidPhone($phone)) { return array('status' => 0, 'message' => $register->getLastError()); /* 判断用户名是否可用 */ } elseif (!$register->isValidName($username)) { return array('status' => 0, 'message' => $register->getLastError()); /* 判断验证码是否正确 */ } elseif (!$register->isValidRegCode($code, $phone)) { return array('status' => 0, 'message' => $register->getLastError()); /* 判断头像传递信息是否完整 */ } elseif (!$avatarUrl or !$avatarW or !$avatarH) { return array('status' => 0, 'message' => '用户头像上传不完整'); /* 密码判断 */ } elseif (!$register->isValidPasswordNoRepeat($password)) { return array('status' => 0, 'message' => $register->getLastError()); /* 格式化地区地址判断 */ } elseif (!$location) { return array('status' => 0, 'message' => '格式化地区地址不能为空'); /* 地区判断 */ } elseif (!$province or !$city) { return array('status' => 0, 'message' => '请完整的选择地区'); } $userData = array('login_salt' => rand(10000, 99999)); // 用户基本资料数组 $userData['password'] = model('User')->encryptPassword($password, $userData['login_salt']); // 用户密码 $userData['uname'] = $username; // 用户名 $userData['phone'] = $phone; // 用户手机号码 $userData['sex'] = $sex; // 用户性别 $userData['location'] = $location; // 格式化地址 $userData['province'] = $province; // 省 $userData['city'] = $city; $userData['area'] = $area; // 地区 $userData['intro'] = $intro; // 用户简介 $userData['ctime'] = time(); // 注册时间 $userData['reg_ip'] = get_client_ip(); // 注册IP /* 用户是否默认审核 */ $userData['is_audit'] = 1; $config['register_audit'] and $userData['is_audit'] = 0; $userData['is_active'] = 1; // 默认激活 $userData['is_init'] = 1; // 默认初始化 $userData['first_letter'] = getFirstLetter($username); // 用户首字母 /* 用户搜索 */ $userData['search_key'] = $username . ' ' . $userData['first_letter']; preg_match('/[\\x7f-\\xff]+/', $username) and $userData['search_key'] .= ' ' . Pinyin::getShortPinyin($username, 'utf-8'); $uid = model('User')->add($userData); // 添加用户数据 if (!$uid) { return array('status' => 0, 'message' => '注册失败'); } // 注册失败的提示 /* 添加默认用户组 */ $userGroup = $config['default_user_group']; empty($userGroup) and $userGroup = C('DEFAULT_GROUP_ID'); is_array($userGroup) and $userGroup = implode(',', $userGroup); model('UserGroupLink')->domoveUsergroup($uid, $userGroup); /* 添加双向关注用户 */ if (!empty($config['each_follow'])) { model('Follow')->eachDoFollow($uid, $config['each_follow']); } /* 添加默认关注用户 */ $defaultFollow = $config['default_follow']; $defaultFollow = explode(',', $defaultFollow); $defaultFollow = array_diff($defaultFollow, explode(',', $config['each_follow'])); empty($defaultFollow) or model('Follow')->bulkDoFollow($uid, $defaultFollow); /* 保存用户头像 */ $avatarData = array('picurl' => $avatarUrl, 'picwidth' => $avatarW); $scaling = 5; // 未知参数 $avatarData['w'] = $avatarW * $scaling; $avatarData['h'] = $avatarH * $scaling; $avatarData['x1'] = 0; $avatarData['y1'] = 0; $avatarData['x2'] = $avatarData['w']; $avatarData['y2'] = $avatarData['h']; model('Avatar')->init($uid)->dosave($avatarData, true); if ($userData['is_audit'] == 1) { $_POST['login'] = $phone; $_POST['password'] = $password; return $this->authorize(); } return array('status' => 2, 'message' => '注册成功,请等待审核'); }
/** * Get class instance. * * @return \Overtrue\Pinyin\Pinyin */ public static function getInstance() { if (is_null(self::$_instance)) { self::$_instance = new static(); } return self::$_instance; }
<?php include_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '../../../../init.php'; Passport::RequireLogin(); if ($_FILES) { $ret = array(); foreach ($_FILES as $file) { $success = false; $errReason = ""; if ($file['size'] == 0) { $errReason = "文件大小为 0 字节。"; } else { @mkdir(UPLOAD_PATH, 0777, true); $new_filename = microtime(true) . '_' . Pinyin::get(str_replace(' ', '-', $file['name'])); $upload_file = UPLOAD_PATH . $new_filename; if (move_uploaded_file($file['tmp_name'], $upload_file)) { $success = true; } } $ret[] = array('Success' => $success, 'ErrReason' => $errReason, 'NewFileName' => UPLOAD_PATH_WWW . $new_filename); } echo json_encode($ret); exit; } ?> <form enctype="multipart/form-data" method="post"> <input type="file" name="file1"> <input type="submit" value="上传"> </form>
require_once 'pinyin/Pinyin.php'; $res = [['real_name' => '哈哈', 'num' => 1], ['real_name' => 'o哈哈', 'num' => 1]]; $sort = []; $numsort = []; $diffsort = []; Pinyin::set('delimiter', ''); Pinyin::set('accent', false); Pinyin::set('uppercase', true); $dict = array(); foreach ($res as $value) { $workName = $value['real_name']; if (isset($dict[$workName])) { $value['pinyin'] = $dict[$workName]['pinyin']; $key = $dict[$workName]['key']; } else { $value['pinyin'] = Pinyin::trans($value['real_name']); $key = getFirstchar($value['pinyin']); $dict[$workName]['pinyin'] = $value['pinyin']; $dict[$workName]['key'] = $key; } $value['num'] = intval($value['num']); unset($value['value']); $id = $value['pinyin']; if ($key == '#') { if (isset($diffsort[$key][$id])) { $diffsort[$key][$id]['num'] = $diffsort[$key][$id]['num'] + $value['num']; } else { $diffsort[$key][$id] = $value; } } elseif ($key == '0-9') { if (isset($numsort[$key][$id])) {
/** * 认证方法 --using * @param varchar oauth_token * @param varchar oauth_token_secret * @return array 状态+提示 */ public function register() { $phone = floatval($this->data['phone']); // 手机号码 $username = '******' . t($this->data['username']); // 用户名 $password = $this->data['password']; // 密码 $sex = intval($this->data['sex']); in_array($sex, array(1, 2)) or $sex = 1; // 默认 男 1.男,2女 $register = model('Register'); $config = model('Xdata')->get('admin_Config:register'); // 配置 /* 判断用户手机号码可用性 */ if (!$register->isValidPhone($phone)) { return array('status' => 0, 'msg' => $register->getLastError()); /* 判断用户名是否可用 */ } elseif (!$register->isValidName($username)) { return array('status' => 0, 'msg' => $register->getLastError()); /* 密码判断 */ } elseif (!$register->isValidPasswordNoRepeat($password)) { return array('status' => 0, 'msg' => $register->getLastError()); } $userData = array('login_salt' => rand(10000, 99999)); // 用户基本资料数组 $userData['password'] = model('User')->encryptPassword($password, $userData['login_salt']); // 用户密码 $userData['uname'] = $username; // 用户名 $userData['phone'] = $phone; // 用户手机号码 $userData['sex'] = $sex; // 用户性别 $userData['ctime'] = time(); // 注册时间 $userData['reg_ip'] = get_client_ip(); // 注册IP /* 用户是否默认审核 */ $userData['is_audit'] = 1; $config['register_audit'] and $userData['is_audit'] = 0; $userData['is_active'] = 1; // 默认激活 $userData['is_init'] = 1; // 默认初始化 $userData['first_letter'] = getFirstLetter($username); // 用户首字母 /* 用户搜索 */ $userData['search_key'] = $username . ' ' . $userData['first_letter']; preg_match('/[\\x7f-\\xff]+/', $username) and $userData['search_key'] .= ' ' . Pinyin::getShortPinyin($username, 'utf-8'); $uid = model('User')->add($userData); // 添加用户数据 if (!$uid) { return array('status' => 0, 'msg' => '注册失败'); } // 注册失败的提示 /* 添加默认用户组 */ $userGroup = $config['default_user_group']; empty($userGroup) and $userGroup = C('DEFAULT_GROUP_ID'); is_array($userGroup) and $userGroup = implode(',', $userGroup); model('UserGroupLink')->domoveUsergroup($uid, $userGroup); /* 添加双向关注用户 */ if (!empty($config['each_follow'])) { model('Follow')->eachDoFollow($uid, $config['each_follow']); } /* 添加默认关注用户 */ $defaultFollow = $config['default_follow']; $defaultFollow = explode(',', $defaultFollow); $defaultFollow = array_diff($defaultFollow, explode(',', $config['each_follow'])); empty($defaultFollow) or model('Follow')->bulkDoFollow($uid, $defaultFollow); return array('status' => 1, 'msg' => '注册成功'); }
public function tag($data, $keywords) { $memkey = MEMPREFIX . 'tag' . $keywords; //$tag = $this->memcache->get($memkey); if ($tag) { return $tag; } foreach ($data as $v) { if (strpos($v['keywords'], ' ')) { $_keywords = explode(' ', $v['keywords']); foreach ($_keywords as $value) { if (strcmp(Pinyin::get($value), $keywords) === 0) { $tag = $value; //$this->memcache->set($memkey, $tag, MEMCACHE_COMPRESSED, 108000); return $tag; } } } else { if (strcmp(Pinyin::get($v['keywords']), $keywords) === 0) { $tag = trim($v['keywords']); //$this->memcache->set($memkey, $tag, MEMCACHE_COMPRESSED, 108000); return $tag; } } } }
public function getUrl() { if (F::utf8_str($this->title) == '1') { $title = str_replace('/', '-', $this->title); } else { $pinyin = new Pinyin($this->title); $title = $pinyin->full2(); $title = str_replace('/', '-', $title); } return Yii::app()->createUrl('article/view', array('id' => $this->article_id, 'title' => $title)); }
/** * 转换成拼音 * * @access public * @param string $word 待转换的字符串 * @return string */ public function pinyin($word) { require_once 'Pinyin.php'; $pinyin = new Pinyin(); return $pinyin->stringToPinyin($word); }
<?php include_once 'Pinyin.php'; echo Pinyin::getPinyin("早上好"); echo Pinyin::getShortPinyin("早上好");
/** * load dictionary content * * @return array */ protected function loadDictionary() { $dictFile = __DIR__ . '/data/dict.php'; $ceditDictFile = __DIR__ . '/data/cedict/cedict_ts.u8'; if (!file_exists($dictFile)) { // parse and cache $dictionary = $this->parseDictionary($ceditDictFile); $this->cache($dictFile, $dictionary); // load from cache } else { $dictionary = $this->loadFromCache($dictFile); } return self::$dictionary = $dictionary; }
public function get_urltitle($name = '', $urlname = null, $aid = null) { if (empty($name)) { return false; exit; } if (empty($urlname)) { $pinyin = new Pinyin(); $name = preg_replace('/\\s+/', '-', $name); $pattern = '/[^\\x{4e00}-\\x{9fa5}\\d\\w\\-]+/u'; $name = preg_replace($pattern, '', $name); $urlname = substr($pinyin->output($name, true), 0, 30); if (substr($urlname, 0, 1) == '-') { $urlname = substr($urlname, 1); } if (substr($urlname, -1) == '-') { $urlname = substr($urlname, 0, -1); } } $where = ''; if (!empty($aid)) { $where = 'AND aid<>' . $aid; } $info = $this->model->table('content')->where("urltitle='" . $urlname . "'" . $where)->count(); if (empty($info)) { return $urlname; } else { return $urlname . substr(cp_uniqid(), 8); } }
<?php /** * Created by PhpStorm. * User: jifei * Date: 15/6/25 */ include_once 'Pinyin.php'; echo Pinyin::getPinyin("ну╔¤║├", 'gb2312'); echo Pinyin::getShortPinyin("ну╔¤║├", 'gb2312');