php取出字符串(包括汉字)首字母函数

2017-10-14编程教程
214

<?php
//取出首字母函数

function getfirstchar($s0){ 
if(ord($s0)>="1" and ord($s0)<=ord("z") )   { return strtoupper($s0); } 
//$s=iconv("UTF-8","gb2312", $s0); 如果需要转换为utf-8的话
$s=$s0;//无需转换的情况
$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<=-17923)return "G"; 
if($asc>=-17922 and $asc<=-17418)return "H";               
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";   
return 0; 
}
echo getfirstchar("你好");

?>

The End

相关推荐

layui根据百度地图经纬度在弹出层中显示位置
首先你需要引入百度地图的js script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0ak=你的ak"/script ak ,注意是要浏览器端的ak,这个直接到百度开发者平台申请。 引入layui,这个大家可以到layui官网看看怎么引入layer, 注意:这里要提...
2025-01-09 编程教程
240

百度UEditor编辑器如何禁止过滤div等网页html标签
将设计排版好的页面html代码上传到数据库,再读取出来的时候发现所有的div都被替换成了p标签。 解决方法: 首先在ueditor.all.js文件内搜索allowDivTransToP,找到如下的代码,将true设置为false me.setOpt({ 'allowDivTransToP':false, 'disabledTableInTable'...
2022-11-23 编程教程
495

PHP错误Warning: Cannot modify header information - headers alr
今天在用php进行图片保存输出时候,图片一直显示错误,后面用调试模式下提示:Warning: Cannot modify header information - headers already sent by... 看了一些网上的方法也没解决,最后在php.ini配置output_buffering默认为4096就没有遇到这个错误了: o...
2022-05-18 编程教程
69

Parse error: syntax error, unexpected '&'解决办法
在使用PHP5.4及以上版本时,在调用函数时,使用引用符号时,会出现Parse error: syntax error, unexpected 或PHP Fatal error: Call-time pass-by-reference has been removed者,这是由于在函数调用时通过引用传递参数已被弃用,因为它影响了代码的整洁,如...
2022-05-11 编程教程
295

解析PHP中ob_start()函数的用法
ob_start()函数用于打开缓冲区,比如header()函数之前如果就有输出,包括回车/空格/换行/都会有Header had all ready send by的错误,这时可以先用ob_start()打开缓冲区PHP代码的数据块和echo()输出都会进入缓冲区而不会立刻输出.当然打开缓冲区的作用很多,只要...
2022-05-11 编程教程
106

php中判断一个字符串包含另一个字符串的方法
第一种方法:用php的strpos() 函数判断字符串中是否包含某字符串的方法 if(strpos(www.genban.org,genban) !== false){ echo 包含genban; }else{ echo 不包含genban; } 第二种 使用了explode 用explode进行判断PHP判断字符串的包含代码如下: ?php $name = 00...
2020-03-28 编程教程
403