/** * Displays a particular model. * 如果查询没有子地区,则跳转到当前地区 * @param integer $id the ID of the model to be displayed */ public function actionView($id) { $model = $this->loadModel($id); UtilHelper::writeToFile($model->attributes); if ($model->children == null) { //如果已有人开启了广告栏,则跳转到对应广告栏首页,否则就回到本地首页 if ($model->forerunner) { // 设置cookie信息 $cookies = new CHttpCookie('area', serialize($model->attributes)); $cookies->expire = time() + 60 * 60 * 24 * 30; Yii::app()->request->cookies['area'] = $cookies; $link = $this->createUrl('/site/index', array('area' => Region::model()->getUserArea()->short, 'id' => $model->id)); } else { $link = $this->createUrl('/site/mention', array('region' => $model->region)); } echo 'fail_' . $link; } else { $pinyin = new PinYin(); // echo '<ul>'; foreach ($model->children as $data) { // echo '<li>'; echo CHtml::link($data->region, array('/region/view', 'id' => $data->id, 'area' => $pinyin->words2Short($data->region, 1)), array('onclick' => 'uu.loadRegion($(this));return false;')); // echo '</li>'; } // echo '</ul>'; } }
private function showLinks() { $pinyin = new PinYin(); $data = $this->getData(); foreach ($data as $item) { echo CHtml::link($item->region, array('/region/view', 'id' => $item->id, 'area' => $pinyin->words2Short($item->region, 1)), array('onclick' => 'uu.loadRegion($(this));return false;')); } }
/** * 显示登录页(默认Action) */ function doDefault() { /* {{{ 获取拼音, 待转换汉字编码为UTF8 */ $pinyin = new PinYin(); echo $pinyin->getPinYin("阿斯蒂芬玩儿玩儿234wer1判断是23123地方", "-"); echo "<br />"; /* }}} */ /* {{{ 获取拼音, 待转换汉字编码为GB2312 */ $pinyin = new PinYin('gb2312'); $list = iconv("UTF-8", "GB2312", "阿斯蒂芬玩儿玩儿234wer1判断是23123地方"); echo $pinyin->getPinYin($list, ","); /* }}} */ }
public function actionTest($args = array()) { if (!isset($args[0]) || $args[0] === '') { $this->usageError('请指定要测试的拼音、中文字符串!'); } $input = $args[0]; require_once Yii::getPathOfAlias('application.vendors.PinYin') . '.class.php'; if (preg_match('/[\\x80-\\xff]/', $input)) { echo "拼音转换结果:{$input}\n"; $py = new PinYin($this->dictFile); print_r($py->convert($input)); } else { echo "拼音分割结果:{$input}\n"; print_r(PinYin::segment($input)); } }
/** * 实例化类 * @static * @return self */ public static function init() { if (!is_object(self::$instance)) { self::$instance = new self(); self::$tableCount = count(self::$table); } return self::$instance; }
/** * 返回字符串全拼 * @param $str string */ public static function QP($str) { $str = iconv("utf-8", "gbk", $str); $ret = ""; $len = strlen($str); for ($i = 0; $i < $len; $i++) { $p = ord(substr($str, $i, 1)); if ($p > 160) { $q = ord(substr($str, ++$i, 1)); $p = $p * 256 + $q - 65536; } $ret .= PinYin::_arcichange($p); } return str_replace('?', '', trim('' . $ret)); }
public static function geta() { $uri = 'http://tq.21004.com/'; $data = iconv('GBK', 'UTF-8', \HttpClient::factory()->get($uri)->data()); $d = array(); if (preg_match_all('#<h3>([^<]+)</h3>(.*)<\\/div>#Uis', $data, $m)) { foreach ($m[0] as $k => $v) { $d[$m[1][$k]] = array(); preg_match_all('#target="_blank">([^<]+)<\\/a>#Uis', $m[2][$k], $m2); foreach ($m2[0] as $k2 => $v2) { $d[$m[1][$k]][\PinYin::get($m2[1][$k2])] = $m2[1][$k2]; } } } }
<?php /** * 用户相关数据 * @example * 1.用户地区数据未实现 * 2.用户最后发布微博信息未实现 * @author zivss <*****@*****.**> * @version TS3.0 */ if ($_GET['t'] == 'user') { require_once './extends/PinYin.php'; $Py = new PinYin(); $p = !empty($_GET['p']) ? intval($_GET['p']) : 1; $count = 1000; $user_sql = 'SELECT * FROM `' . $old_db_conf['DB_PREFIX'] . 'user` LIMIT ' . $count * ($p - 1) . ',' . $count . ';'; $user_list = $old_db->query($user_sql); if (empty($user_list)) { // 跳转操作 $t = 'user_other'; $p = 1; echo '<script>window.location.href="' . getJumpUrl($t, $p) . '";</script>'; exit; } else { $data = array(); foreach ($user_list as &$value) { if (empty($value['email'])) { $value['email'] = 'ts_' . $value['uid'] . '@thinksns.com'; } $salt = rand(11111, 99999); $salt = mysql_escape_string($salt);
public function pinyin() { $name = I('name'); $preg = '/^[\\x81-\\xfe][\\x40-\\xfe]+$/'; if (preg_match($preg, $name)) { import('Common/Org/Util/PinYin'); $pinyin = new \PinYin(); $name = $pinyin->Pinyin($name, 1); } echo $name; }
/** * 返回当前字符的拼音 * * @return string */ public function pinyin() { return PinYin::get($this->data); }
/** * 获得文件名全拼及简拼 */ public static function getPinYinByName($name) { $py = new PinYin(); $len = mb_strlen($name, 'utf-8'); $allPY = ""; $firstPY = ""; for ($i = 0; $i < $len; $i++) { $subName = mb_substr($name, $i, 1, "utf-8"); $allPY .= $py->getAllPY($subName); $firstPY .= $py->getFirstPY($subName); } if (empty($allPY)) { $allPY = $firstPY = $name; } $namePY = $allPY . "|" . $firstPY; if (strlen($namePY) > 255) { $namePY = substr($namePY, 0, 254); } return $namePY; }
/** * 保存用户信息 * @return [type] [description] */ public function saveInfo() { $post = I('post.'); $o_info = $this->redis->HGETALL('Userinfo:uid' . $this->mid); $info = array(); //头像 $o_headimg = json_decode($o_info['headimg'], true) ? json_decode($o_info['headimg'], true) : array(); $o_headimg_ids = getSubByKey($o_headimg, 'rid'); $o_headimg_str = $o_headimg_ids ? implode(',', $o_headimg_ids) : ''; if ($o_headimg_str != trim($post['headimg'], ',') && isset($post['headimg'])) { $info['headimg'] = trim($post['headimg'], ','); $headimg_arr = explode(',', $info['headimg']); foreach ($headimg_arr as $v) { $photo_res = array(); $photo_res['rid'] = $v; $photo_res['url'] = C('WEBSITE_URL') . D('picture')->where('id=' . $v)->getField('path'); $photo[] = $photo_res; } $this->redis->HSET('Userinfo:uid' . $this->mid, 'headimg', json_encode($photo, JSON_UNESCAPED_UNICODE)); $new_photo = explode(',', trim($post['headimg'], ',')) ? explode(',', trim($post['headimg'], ',')) : array(); $o_headimg_ids = $o_headimg_ids ? $o_headimg_ids : array(); $add_photo = array_diff($new_photo, $o_headimg_ids); if ($add_photo) { $sj_log['uid'] = $this->mid; $sj_log['type'] = 1; foreach ($add_photo as $v) { $sj_log['url'] = D('picture')->where('id=' . $v)->getField('path'); D('shunjian')->add($sj_log); } } } //昵称 if ($post['uname'] != $o_info['uname'] && isset($post['uname'])) { if ($post['uname'] == '') { $this->return['code'] == 1004; $this->return['message'] == L('uname_null'); $this->goJson($this->return); } $info['uname'] = $post['uname']; load("@.user"); $info['first_letter'] = getFirstLetter($post['uname']); //如果包含中文将中文翻译成拼音 if (preg_match('/[\\x7f-\\xff]+/', $post['uname'])) { import("Common.Util.PinYin"); $pinyinClass = new \PinYin(); $pinyin = $pinyinClass->Pinyin($post['uname']); //昵称和呢称拼音保存到搜索字段 $info['search_key'] = $post['uname'] . ' ' . $pinyin; } else { $info['search_key'] = $post['uname']; } } // 性别 if ($post['sex'] != $o_info['sex'] && isset($post['sex'])) { if ($post['sex'] != 1 && $post['sex'] != 2) { $this->return['code'] == 1003; $this->return['message'] == L('sex_error'); $this->goJson($this->return); } $info['sex'] = $post['sex']; $sex_flag = $post['sex'] == 1 ? 2 : 1; $this->redis->sRem('User:sex' . $sex_flag, $this->mid); $this->redis->sAdd('User:sex' . $info['sex'], $this->mid); } // 个性签名 if ($post['intro'] != $o_info['intro'] && isset($post['intro'])) { $info['intro'] = $post['intro']; } // 视频介绍 $o_info['video_profile'] = json_decode($o_info['video_profile'], true) ? json_decode($o_info['video_profile'], true) : array(); if ($post['video_profile'] != $o_info['video_profile']['rid'] && isset($post['video_profile'])) { $info['video_profile'] = $post['video_profile']; $video = D('file')->field('savepath, savename')->where('id=' . $post['video_profile'])->find(); $video_profile['rid'] = $post['video_profile']; $video_profile['url'] = C('WEBSITE_URL') . '/Uploads/File/' . $video['savepath'] . $video['savename']; $this->redis->HSET('Userinfo:uid' . $this->mid, 'video_profile', json_encode($video_profile, JSON_UNESCAPED_UNICODE)); $video_profile_data['type'] = 2; $video_profile_data['url'] = '/Uploads/File/' . $video['savepath'] . $video['savename']; $video_profile_data['uid'] = $this->mid; D('shunjian')->add($video_profile_data); unset($video_profile_data); } // 音频介绍 $o_info['audio_profile'] = json_decode($o_info['audio_profile'], true) ? json_decode($o_info['audio_profile'], true) : array(); if ($post['audio_profile'] != $o_info['audio_profile']['rid'] && $post['audio_profile']) { $info['audio_profile'] = $post['audio_profile']; $audio = D('file')->field('savepath, savename')->where('id=' . $post['audio_profile'])->find(); $audio_profile['rid'] = $post['audio_profile']; $audio_profile['url'] = C('WEBSITE_URL') . '/Uploads/File/' . $audio['savepath'] . $audio['savename']; $this->redis->HSET('Userinfo:uid' . $this->mid, 'audio_profile', json_encode($audio_profile, JSON_UNESCAPED_UNICODE)); } // 国家,省,城市信息 if (isset($post['country']) && $post['country'] != 0) { if ($post['country'] != $o_info['country']) { $info['country'] = $post['country']; $info['province'] = $post['province']; $info['city'] = $post['city']; $info['location'] = $post['location']; } elseif ($post['province'] != $o_info['province'] && isset($post['province'])) { $info['province'] = $post['province']; $info['city'] = $post['city']; $info['location'] = $post['location']; } elseif ($post['city'] != $o_info['city'] && isset($post['city'])) { $info['city'] = $post['city']; $info['location'] = $post['location']; } } //语言 更改 $o_language = json_decode($o_info['language'], true) ? json_decode($o_info['language'], true) : array(); if ($post['language']['lid'] != $o_language['lid'] && isset($post['language']['lid'])) { $info['cur_language'] = $language['lid'] = $post['language']['lid']; } if ($post['language']['self_level'] != $o_language['self_level'] && isset($post['language']['self_level'])) { $info['level'] = $language['self_level'] = $post['language']['self_level']; } if (count($language)) { D('userLanguage')->where('uid=' . $this->mid)->save($language); $language = D('userLanguage')->where('uid=' . $this->mid)->field('lid, type, sys_level, self_level')->select(); $allLanguage = D('language')->getAllLanguage(); foreach ($language as $k => $v) { $language[$k]['language_name'] = $allLanguage[$v['lid']]; } $this->redis->HSET('Userinfo:uid' . $this->mid, 'language', json_encode($language, JSON_UNESCAPED_UNICODE)); } if (count($info)) { D('userinfo')->where('uid=' . $this->mid)->save($info); unset($info['video_profile'], $info['headimg'], $info['audio_profile']); foreach ($info as $k => $v) { $this->redis->HSET('Userinfo:uid' . $this->mid, $k, $v); } } //标签 if (isset($post['tags'])) { $o_tags = json_decode($o_info['tags']) ? json_decode($o_info['tags'], true) : array(); $o_tag_ids = getSubByKey($o_tags, 'tid'); $tags_post = explode(',', $post['tags']); if (!count($tags_post)) { D('userTags')->where('uid=' . $this->mid)->delete(); } else { $tags['uid'] = $this->mid; //有新增标签 $add_tags = array_diff($tags_post, $o_tag_ids); if (count($add_tags)) { foreach ($add_tags as $v) { $tags['tid'] = $v; D('userTags')->add($tags); } } //有删除标签 $delete_tags = array_diff($o_tag_ids, $tags_post); if (count($delete_tags)) { foreach ($delete_tags as $v) { D('userTags')->where('uid=' . $this->mid . ' and tid=' . $v)->delete(); } } //如果有变化,取出该用户全部标签进行缓存 if (count($delete_tags) || count($add_tags)) { $allTags = D('tags')->getAllTags(); $tags_res = D('userTags')->field('tid')->where('uid=' . $this->mid)->select(); foreach ($tags_res as $k => $val) { $tags_res[$k]['tag_name'] = $allTags[$val['tid']]; } $this->redis->HSET('Userinfo:uid' . $this->mid, 'tags', json_encode($tags_res, JSON_UNESCAPED_UNICODE)); } } } //$this->return['data'] = $this->getUserinfoData($this->mid); $this->goJson($this->return); }
/** * 根据用户名与昵称获得拼音 * @param $name * @param $nick * @return string */ private function getPinYinByName($name, $nick) { $py = new PinYin(); $allPY = $py->getAllPY($name); $firstPY = $py->getFirstPY($name); $namePY = $allPY . "|" . $firstPY; $allPY = $py->getAllPY($nick); $firstPY = $py->getFirstPY($nick); $nickPY = $allPY . "|" . $firstPY; return $namePY . "|" . $nickPY; }
public static function getNamePinYin($name) { $pinyin = new PinYin(); return $pinyin->words2PinYin($name, 'UTF-8'); }
} elseif (!empty($lastDigit)) { //仅保留一个零(上一个数字是零时) $zhNumSub .= strrev('零'); //不用再加单位weight } $lastDigit = $digit; } $zhNumSub && ($zhNum .= self::$units[$k] . $zhNumSub); //去掉大单位 } return strrev($zhNum); } } //按拼音首字母排序 $arr = array('成都' => '028', '北京' => '010'); PinYin::ukrsort($arr); var_dump($arr); class PinYin { /** * * 比较拼音首字母(基于字符是按拼音顺序编码) */ static function cmp(&$a, &$b) { $a = iconv('utf-8', 'gbk', $a); $a = $a[0]; $b = iconv('utf-8', 'gbk', $b); $b = $b[0]; if ($a == $b) { return 0;
<?php $pinyin = new PinYin(); ?> <?php foreach ($model as $item) { ?> <li data-id="<?php echo $pinyin->words2PinYin($item->name); ?> " style="width:<?php echo rand(100, 200); ?> ;"> <?php echo CHtml::image(Channel::model()->getChannelIco($item->id), $item->name); ?> <?php echo $item->name; ?> </li> <?php } ?> <?php $this->widget('ext.yiinfinite-scroll.YiinfiniteScroller', array('contentSelector' => '#channelBox', 'itemSelector' => 'li', 'loadingText' => '<hr /><img src="/public/images/loading.gif" />', 'donetext' => '<hr />This is the end... my only friend, the end', 'pages' => $pages));
<?php /* * @copyright Leyun internet Technology(Shanghai)Co.,Ltd * @license http://www.dzzoffice.com/licenses/license.txt * @package DzzOffice * @link http://www.dzzoffice.com * @author zyx(zyx@dzz.cc) */ if (!$_G['uid']) { exit; } //error_reporting(E_ALL); include_once libfile('function/organization'); include_once dzz_libfile('class/pinyin'); $py = new PinYin(); $data = array(); $term = trim($_GET['term']); $filter = intval($_GET['filter']); //0:机构和用户;1:仅用户;2:仅机构 if ($filter == 1 || !$filter) { $param_user = array('user', 'user_status'); $sql_user = "******"; if ($term) { $sql_user .= " and username LIKE %s"; $param_user[] = '%' . $term . '%'; } foreach (DB::fetch_all("select u.uid,u.username from %t u LEFT JOIN %t s on u.uid=s.uid {$sql_user} order by s.lastactivity DESC limit 10", $param_user) as $value) { if ($value['uid'] != $_G['uid']) { $data[] = array('name' => $value['username'], 'searchkey' => $py->getAllPY($value['username']) . $value['username'], 'id' => 'u' . $value['uid'], 'icon' => 'avatar.php?uid=' . $value['uid'] . '&size=small', 'title' => $value['username'] . ':' . 'u' . $value['uid']); }
<?php $pinyin = new PinYin(); $user = User::model()->findByPk($data->forerunner); $short = $pinyin->words2Short(Region::model()->getAreaName($user->profiles->county)); ?> <div class="roundSection left" style="width:190px;text-align:center;margin:0 20px;padding:5px;"> <?php echo CHtml::link(CHtml::image('/public/images/logo.png', Region::model()->getAreaBrandName($user->profiles->county)), array('site/index', 'id' => $user->profiles->county, 'area' => Region::model()->getAreaBrandShortName($user->profiles->county)), array('class' => 'left', 'title' => Profile::model()->getUserAddress($data->forerunner, '>'), 'style' => 'padding:10px;padding:0px;font-size:60px;font-family:TTF;font-weight:bolder;overflow:hidden;')); ?> <div class="right" style="position:absolute;top:50px;right:5px;font-size:12px;"> <?php echo Region::model()->getAreaBrandName($user->profiles->county); ?> 广告栏 </div> <hr /> <?php echo date('m月d日'); ?> </div>
/** * 完善第三方登录用户信息 * @return [type] [description] */ public function ologinPrefect() { $post = I('post.'); // 验证手机号 $mobile = I('post.mobile'); if (strlen($mobile) != 11) { $this->return['code'] = 1001; $this->return['message'] = L('mobile_error'); $this->goJson($this->return); } if ($this->checkMobile($mobile)) { $this->return['code'] = 1002; $this->return['message'] = L('mobile_has'); $this->goJson($this->return); } // 验证昵称 if (!$post['uname']) { $this->return['code'] = 1003; $this->return['message'] = L('uname_null'); $this->goJson($this->return); } // 验证性别 if ($post['sex'] != 1 && $post['sex'] != 2) { $this->return['code'] = 1004; $this->return['message'] = L('sex_error'); $this->goJson($this->return); } load("@.user"); $post['first_letter'] = getFirstLetter($post['uname']); //如果包含中文将中文翻译成拼音 if (preg_match('/[\\x7f-\\xff]+/', $post['uname'])) { import("Common.Util.PinYin"); $pinyinClass = new \PinYin(); $pinyin = $pinyinClass->Pinyin($post['uname']); //昵称和呢称拼音保存到搜索字段 $post['search_key'] = $post['uname'] . ' ' . $pinyin; } else { $post['search_key'] = $post['uname']; } // 密码 if (!$post['password']) { $this->return['code'] = 1004; $this->return['message'] = L('pwd_null'); $this->goJson($this->return); } $post['login_salt'] = rand(11111, 99999); $post['password'] = md5(md5($post['password']) . $post['login_salt']); $post['ctime'] = time(); $post['level'] = $post['self_level']; $post['cur_language'] = $post['lid']; D('userinfo')->where('uid=' . $this->mid)->save($post); $language_info['uid'] = $this->mid; $language_info['lid'] = $post['lid']; $language_info['type'] = 4; $language_info['self_level'] = $post['self_level']; D('userLanguage')->add($language_info); $this->redis->Sadd('User:sex' . $post['sex'], $this->mid); $this->redis->SADD('Userinfo:online', $this->mid); //在线用户列表 $this->createSubAccount('yujia' . $this->mid, $this->mid); $res = D('userinfo')->getUserInfo($this->mid); $this->redis->HMSET('Userinfo:uid' . $this->mid, $res); $res['token'] = I('post.token'); $tmp['headimg'] = json_decode($this->redis->HGET('Userinfo:uid' . $this->mid, 'headimg'), true); $tmp['headimg'] = $tmp['headimg'][0]['url']; $return = array('uid' => $this->mid, 'token' => $res['token'], 'voipaccount' => $res['voipaccount'], 'voippwd' => $res['voippwd'], 'subaccountid' => $res['subaccountid'], 'subtoken' => $res['subtoken'], 'uname' => $res['uname'], 'mobile' => $res['mobile'], 'sex' => $res['sex'], 'headimg' => $tmp['headimg']); $this->return['data'] = $return; $this->goJson($this->return); }
/** * 获取广告简写 * @param unknown_type $id */ public function getAreaBrandShortName($id) { $pinyin = new PinYin(); return $pinyin->words2Short(self::getAreaBrandName($id)); }