php 按照中文字母名字排序,并把相应的头像显示出来
//排序
public function getFirstChar($s){
$s0 = mb_substr($s,0,3); //获取名字的姓
$s = iconv('UTF-8','gb2312', $s0); //将UTF-8转换成GB2312编码
$x =ord($s0);
if (ord($s0)>128) { //汉字开头,汉字没有以U、V开头的
$asc=ord($s{0})*256+ord($s{1})-65536;
if($asc>=-20319 and $asc<=-20284)return "A";
if($asc>=-20283 and $asc<=-19776)return "B";
if($asc>=-19775 and $asc<=-19219)return "C";
if($asc>=-19218 and $asc<=-18711)return "D";
if($asc>=-18710 and $asc<=-18527)return "E";
if($asc>=-18526 and $asc<=-18240)return "F";
if($asc>=-18239 and $asc<=-17760)return "G";
if($asc>=-17759 and $asc<=-17248)return "H";
if($asc>=-17247 and $asc<=-17418)return "I";
if($asc>=-17417 and $asc<=-16475)return "J";
if($asc>=-16474 and $asc<=-16213)return "K";
if($asc>=-16212 and $asc<=-15641)return "L";
if($asc>=-15640 and $asc<=-15166)return "M";
if($asc>=-15165 and $asc<=-14923)return "N";
if($asc>=-14922 and $asc<=-14915)return "O";
if($asc>=-14914 and $asc<=-14631)return "P";
if($asc>=-14630 and $asc<=-14150)return "Q";
if($asc>=-14149 and $asc<=-14091)return "R";
if($asc>=-14090 and $asc<=-13319)return "S";
if($asc>=-13318 and $asc<=-12839)return "T";
if($asc>=-12838 and $asc<=-12557)return "W";
if($asc>=-12556 and $asc<=-11848)return "X";
if($asc>=-11847 and $asc<=-11056)return "Y";
if($asc>=-11055 and $asc<=-10247)return "Z";
}else if(ord($s)>=48 and ord($s)<=57){ //数字开头
switch(iconv_substr($s,0,1,'utf-8')){
case 1:return "Y";
case 2:return "E";
case 3:return "S";
case 4:return "S";
case 5:return "W";
case 6:return "L";
case 7:return "Q";
case 8:return "B";
case 9:return "J";
case 0:return "L";
}
}else if(ord($s)>=65 and ord($s)<=90){ //大写英文开头
return substr($s,0,1);
}else if(ord($s)>=97 and ord($s)<=122){ //小写英文开头
return strtoupper(substr($s,0,1));
}
else
{
return iconv_substr($s0,0,1,'utf-8');
//中英混合的词语,不适合上面的各种情况,因此直接提取首个字符即可
}
}
// 拼友列表
public function doPageFriend(){
global $_GPC,$_W;
$uniacid = $_W['uniacid'];
$friends = pdo_fetchall("SELECT * FROM ".tablename("pinba_pinyou")."where uniacid=:uniacid",array(":uniacid"=>$uniacid));
foreach($friends as &$value){
$userName[] = array("name"=>$value['x_name'],"thumb"=>$_W['attachurl'].$value['x_thumb']);
}
$charArray = $this->addPeople($userName);
return $this->result(0,"success",$charArray);
}
public function addPeople($userName)
{
sort($userName);
foreach($userName as &$name){
$char = $this->getFirstChar($name['name']);
$nameArray = array();
if(count($charArray[$char])!=0){
$nameArray = $charArray[$char];
}
array_push($nameArray,$name);
$charArray[$char] = $nameArray;
}
ksort($charArray);
return $charArray;
}
前台显示

php 按照中文字母名字排序,并把相应的头像显示出来的更多相关文章
- js中实现中文按字母拼音排序
js中实现中文按字母拼音排序 var Pinyin = (function (){ var Pinyin = function (ops){ this.initialize(ops); }, opti ...
- IOS数组按中文关键字以字母序排序
本文转载至 http://blog.csdn.net/xunyn/article/details/7882087 iosobjective cuser框架通讯 IOS项目中会用到对通讯录的联系人或是会 ...
- php里获取第一个中文首字母并排序
需求里结算首页需要按门店的首字母A-Z排序.我的数据结构原本是这样的: Array ( [0] => Array ( [sid] => 2885842 [recetcstoredpay] ...
- 本地化下按首字母分组排序的神器——UILocalizedIndexedCollation
最近在整一个很简单的通讯录相关的项目,通讯录当然就少不了按首字母或者汉字拼音首字母分组排序索引.因为按照我一贯的的做法,都是想要做成更通用的.支持本地化的,所以这就纠结了,世界各地的语言啊我去,我顶多 ...
- 在PHP中,将一个汉字数组按照拼音首字母进行排序
(之前发的这篇博文因为含有敏感关键字,只好重发一遍了) <?php $str = "我们可以在浏览器中看到,当鼠标移到元素上时,元素开始向右移动,开始比较慢,之后则比较快,移开时按原曲 ...
- PHP读取文件夹目录,按时间排序,大小排序,名字排序
工作中有时候会遇到文件存储数据,但是在前台显示的时候又因为没有数据库,无法使用上传或最后一次修改日期字段排序,所以有了如下代码: <?php $dir = "./";//目录 ...
- sql server 利用首字母拼音排序和笔画排序的语句
--按笔画排序 select * from Student order by Sname COLLATE Chinese_PRC_Stroke_CS_AS_KS_WS --按字母拼音排序 select ...
- localeCompare() 方法实现中文的拼音排序
google了很多次才发现在国外网站上有提示如何比较中文,原文地址:http://www.webdeveloper.com/forum/showthread.php?t=9365 前提:使用Unico ...
- Oracle 如何对中文字段进行排序
Oracle 如何对中文字段进行排序 oracle中drop.delete和truncate的区别 oracle里的执行计划-查看
随机推荐
- java框架之Shiro-安全/权限框架
准备 简介 Apache Shiro 是 Java 的一个安全(权限)框架. Shiro 不仅可以用在 JavaSE 环境,也可以用在 JavaEE 环境. Shiro 可以完成:认证.授权.加密.会 ...
- python基础之 列表,元组,字典
other help(str.strip) #查看是否有返回值以及返回值类型[] :称为索引操作符 1.列表 列表相比字符串来说能存储大量数据的python的基本数据类型,并且也拥有字符串的一些方法( ...
- Java命令行参数解析
参考 http://blog.csdn.net/mldxs/article/details/36204079 http://rensanning.iteye.com/blog/2161201 imp ...
- mysql查看当前执行线程_关闭当前的某些线程 show processlist_kill
每个与mysqld的连接都在一个独立的线程里运行,您可以使用SHOW PROCESSLIST语句查看哪些线程正在运行,并使用KILL thread_id语句终止一个线程. 如果您拥有SUPER权限,您 ...
- OpenStack-Neutron-安全组
neutron中目前安全组的实现是使用iptables来实现的 创建安全组 创建安全组的时候默认有两条“出”规则(ipv4和ipv6) “default”安全组不仅有“出”规则,还有“入”规则.默认有 ...
- vue的一些感想
如今vue2.0是主流,但是它的路由确实直接从1.0过来的,其中包括组件包括全局组件和局部组件,写好组件之后,我们就需要 使用路由,将组件关联起来,关联起来之后,然后我们才可以将组件的内容通过hash ...
- java开发中中文编码问题
//ajax以get方式提交,字符串中包含中文 //后台struts中对该string的set方法中 this.jsonString = new String(jsoString.getBytes(& ...
- 简单代码生成csv文件(excel)
$arr = array('');// 目标数组 header("Content-Type:application/vnd.ms-excel;charset=gbk"); head ...
- python爬虫——与不断变化的页面死磕和更新换代(3)
经过上一次的实战,手感有了,普罗西(雾)池也有了,再战taobao/tmall 试着使用phantomJS爬手机端,结果发现爬来的tmall页面全是乱码,taobao页面xpath识别错误.一顿分析了 ...
- jQuery 筛选器2
jQuery 筛选器2 // 由于$()只能输入字符串$('#li:eq(1)'),可通过.eq()来传入. // 获取this标签中的指定属性 $(this).eq(1) // 获取第一个元素 $( ...