好得很程序员自学网
  • 首页
  • 后端语言
    • C#
    • PHP
    • Python
    • java
    • Golang
    • ASP.NET
  • 前端开发
    • Angular
    • react框架
    • LayUi开发
    • javascript
    • HTML与HTML5
    • CSS与CSS3
    • jQuery
    • Bootstrap
    • NodeJS
    • Vue与小程序技术
    • Photoshop
  • 数据库技术
    • MSSQL
    • MYSQL
    • Redis
    • MongoDB
    • Oracle
    • PostgreSQL
    • Sqlite
    • 数据库基础
    • 数据库排错
  • CMS系统
    • HDHCMS
    • WordPress
    • Dedecms
    • PhpCms
    • 帝国CMS
    • ThinkPHP
    • Discuz
    • ZBlog
    • ECSHOP
  • 高手进阶
    • Android技术
    • 正则表达式
    • 数据结构与算法
  • 系统运维
    • Windows
    • apache
    • 服务器排错
    • 网站安全
    • nginx
    • linux系统
    • MacOS
  • 学习教程
    • 前端脚本教程
    • HTML与CSS 教程
    • 脚本语言教程
    • 数据库教程
    • 应用系统教程
  • 新技术
  • 编程导航
    • 区块链
    • IT资讯
    • 设计灵感
    • 建站资源
    • 开发团队
    • 程序社区
    • 图标图库
    • 图形动效
    • IDE环境
    • 在线工具
    • 调试测试
    • Node开发
    • 游戏框架
    • CSS库
    • Jquery插件
    • Js插件
    • Web框架
    • 移动端框架
    • 模块管理
    • 开发社区
    • 在线课堂
    • 框架类库
    • 项目托管
    • 云服务

当前位置:首页>后端语言>PHP
<tfoot draggable='sEl'></tfoot>

php获取首写字母 php首字母大写函数

很多站长朋友们都不太清楚php获取首写字母,今天小编就来给大家整理php获取首写字母,希望对各位有所帮助,具体内容如下:

本文目录一览: 1、 [转载]PHP如何取得汉字的拼音首字母 2、 求php获取首字母方法 3、 php获取字符串首字母 4、 php批量获取首字母(汉字、数字、英文) 5、 [php教程]如何用PHP实现取字符的首字母? 6、 PHP自定义函数获取汉字首字母的方法 [转载]PHP如何取得汉字的拼音首字母

函数返

单

汉字

拼音首字母

需要处理

文字符串

需要重新写

函数

用

取

串汉字

拼音首字母

$s1);if($s2==$zh){$zh=$s1;}for($i=0;$i<strlen($zh);$i++){$s1=substr($zh,$i,1);$p=ord($s1);if($p160){$s2=substr($zh,$i++,2);$ret.=

求php获取首字母方法

function ($str){

$s1  = iconv('UTF-8','gb2312',$str);

$s2  = iconv('gb2312','UTF-8',$s1);

$s   = $s2 == $str ? $s1 : $str;

$asc = ord($s{0}) * 256 + ord($s{1}) - 65536;

if($asc >= -20319  $asc <= -20284) return 'a';

if($asc >= -20283  $asc <= -19776) return 'b';

if($asc >= -19775  $asc <= -19219) return 'c';

if($asc >= -19218  $asc <= -18711) return 'd';

if($asc >= -18710  $asc <= -18527) return 'e';

if($asc >= -18526  $asc <= -18240) return 'f';

if($asc >= -18239  $asc <= -17923) return 'g';

if($asc >= -17922  $asc <= -17418) return 'h';

if($asc >= -17417  $asc <= -16475) return 'j';

if($asc >= -16474  $asc <= -16213) return 'k';

if($asc >= -16212  $asc <= -15641) return 'l';

if($asc >= -15640  $asc <= -15166) return 'm';

if($asc >= -15165  $asc <= -14923) return 'n';

if($asc >= -14922  $asc <= -14915) return 'o';

if($asc >= -14914  $asc <= -14631) return 'p';

if($asc >= -14630  $asc <= -14150) return 'q';

if($asc >= -14149  $asc <= -14091) return 'r';

if($asc >= -14090  $asc <= -13319) return 's';

if($asc >= -13318  $asc <= -12839) return 't';

if($asc >= -12838  $asc <= -12557) return 'w';

if($asc >= -12556  $asc <= -11848) return 'x';

if($asc >= -11847  $asc <= -11056) return 'y';

if($asc >= -11055  $asc <= -10247) return 'z';

return null;

};

这是一个传入汉字,通过汉字的ASCII码来判断汉字的首字母的方法。已经调试,可以直接使用。望测试。

php获取字符串首字母

他是根据汉字gb2312编码的头两个字符的范围来区分的。

识别不出很正常,因为gb2312本身包含的汉字就不全。你搜个utf8汉字转拼音的,你再修改下取个首字符。应该好点

php批量获取首字母(汉字、数字、英文)

php批量获取首字母(汉字 数字 英文)

$mysql_server_name= ; //改成自己的mysql数据库服务器

$mysql_username= 用户 ; //改成自己的mysql数据库用户名

$mysql_password= 密码 ; //改成自己的mysql数据库密码

$mysql_database= 数据库 ; //改成自己的mysql数据库名

mysql_connect( $mysql_username $mysql_password) or die( database not access );

mysql_select_db($mysql_database);

mysql_query("SET NAMES utf ");

$equery = " select title from 表 ";

$result =mysql_query($equery );

while ($row = mysql_fetch_array($result MYSQL_BOTH))

{

$title=$row["title"];

if (ord($title)> ) { //汉字开头

echo $letter=getfirstchar($title);

}else if(ord($title)>= and ord($title)<= ){ //数字开头

echo $letter=iconv_substr($title utf );

}else if(ord($title)>= and ord($title)<= ){ //大写英文开头

echo $letter=iconv_substr($title utf );

}else if(ord($title)>= and ord($title)<= ){ //小写英文开头

echo $letter=iconv_substr($title utf );

}

}

function getfirstchar($s ){

$s=iconv("UTF " "gb " $s );

$asc=ord($s{ })* +ord($s{ }) ;

if($asc>= and $asc<= )return "A";

if($asc>= and $asc<= )return "B"; if($asc>= and $asc<= )return "C";

if($asc>= and $asc<= )return "D";

if($asc>= and $asc<= )return "E";

if($asc>= and $asc<= )return "F";

if($asc>= and $asc<= )return "G";

if($asc>= and $asc<= )return "H";

if($asc>= and $asc<= )return "J";

if($asc>= and $asc<= )return "K";

if($asc>= and $asc<= )return "L";

if($asc>= and $asc<= )return "M";

if($asc>= and $asc<= )return "N";

if($asc>= and $asc<= )return "O";

if($asc>= and $asc<= )return "P";

if($asc>= and $asc<= )return "Q";

if($asc>= and $asc<= )return "R";

if($asc>= and $asc<= )return "S";

if($asc>= and $asc<= )return "T";

if($asc>= and $asc<= )return "W";

if($asc>= and $asc<= )return "X";

if($asc>= and $asc<= )return "Y";

if($asc>= and $asc<= )return "Z";

return false;

lishixinzhi/Article/program/PHP/201311/20913

[php教程]如何用PHP实现取字符的首字母?

<?php

function getfirstchar($s0){   

$c=ereg('[a-zA-Z]', strtoupper(substr( $s0, 0, 1 )));

        if($c){

return strtoupper(substr( $s0, 0, 1 )) ;

}else{

            

if($fchar>=ord("a") and $fchar<=ord("Z") )return strtoupper($s0{0});

if(is_numeric(substr( $s0, 0, 1 ))){

$s0 =ToChinaseNum (substr( $s0, 0, 1 ));

    }

$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 null;

}

}

function ToChinaseNum($num)

 {

    $char = array("零","一","二","三","四","五","六","七","八","九");

    $dw = array("","十","百","千","万","亿","兆");

    $retval = "";

    $proZero = false;

    for($i = 0;$i < strlen($num);$i++)

    {

        if($i > 0)    $temp = (int)(($num % pow (10,$i+1)) / pow (10,$i));

        else $temp = (int)($num % pow (10,1));

        

        if($proZero == true  $temp == 0) continue;

        

        if($temp == 0) $proZero = true;

        else $proZero = false;

        

        if($proZero)

        {

            if($retval == "") continue;

            $retval = $char[$temp].$retval;

        }

        else $retval = $char[$temp].$dw[$i].$retval;

    }

    if($retval == "一十") $retval = "十";

    return $retval;

 }

var_dump(getfirstchar("89ssss"));

?>

PHP自定义函数获取汉字首字母的方法

本文实例讲述了PHP自定义函数获取汉字首字母的方法。分享给大家供大家参考,具体如下:

首字母很重要,可以进行排序使用。

城市列表等等。

<?php

/*

*

Created

on

2016-12-1

*/

function

getFirstCharter($str)

{

if

(empty($str))

{

return

'';

}

$fchar

=

ord($str{0});

if

($fchar

>=

ord('A')

$fchar

<=

ord('z'))

return

strtoupper($str{0});

$s1

=

iconv('UTF-8',

'gb2312',

$str);

$s2

=

iconv('gb2312',

'UTF-8',

$s1);

$s

=

$s2

==

$str

?

$s1

:

$str;

$asc

=

ord($s{0})

*

256

+

ord($s{1})

-

65536;

if

($asc

>=

-20319

$asc

<=

-20284)

return

'A';

if

($asc

>=

-20283

$asc

<=

-19776)

return

'B';

if

($asc

>=

-19775

$asc

<=

-19219)

return

'C';

if

($asc

>=

-19218

$asc

<=

-18711)

return

'D';

if

($asc

>=

-18710

$asc

<=

-18527)

return

'E';

if

($asc

>=

-18526

$asc

<=

-18240)

return

'F';

if

($asc

>=

-18239

$asc

<=

-17923)

return

'G';

if

($asc

>=

-17922

$asc

<=

-17418)

return

'H';

if

($asc

>=

-17417

$asc

<=

-16475)

return

'J';

if

($asc

>=

-16474

$asc

<=

-16213)

return

'K';

if

($asc

>=

-16212

$asc

<=

-15641)

return

'L';

if

($asc

>=

-15640

$asc

<=

-15166)

return

'M';

if

($asc

>=

-15165

$asc

<=

-14923)

return

'N';

if

($asc

>=

-14922

$asc

<=

-14915)

return

'O';

if

($asc

>=

-14914

$asc

<=

-14631)

return

'P';

if

($asc

>=

-14630

$asc

<=

-14150)

return

'Q';

if

($asc

>=

-14149

$asc

<=

-14091)

return

'R';

if

($asc

>=

-14090

$asc

<=

-13319)

return

'S';

if

($asc

>=

-13318

$asc

<=

-12839)

return

'T';

if

($asc

>=

-12838

$asc

<=

-12557)

return

'W';

if

($asc

>=

-12556

$asc

<=

-11848)

return

'X';

if

($asc

>=

-11847

$asc

<=

-11056)

return

'Y';

if

($asc

>=

-11055

$asc

<=

-10247)

return

'Z';

return

null;

}

$firstChar

=

getFirstCharter('脚本之家');

print_r($firstChar);//输出:J

?>

更多关于PHP相关内容感兴趣的读者可查看本站专题:《php常用函数与技巧总结》、《PHP数组(Array)操作技巧大全》、《php字符串(string)用法总结》、《PHP错误与异常处理方法总结》、《PHP基本语法入门教程》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家PHP程序设计有所帮助。

关于php获取首写字母的介绍到此就结束了,不知道本篇文章是否对您有帮助呢?如果你还想了解更多此类信息,记得收藏关注本站,我们会不定期更新哦。

查看更多关于php获取首写字母 php首字母大写函数的详细内容...

声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did194861
更新时间:2023-04-26   阅读:37次

上一篇: aligeniephp的简单介绍

下一篇:index和php代码 phpcode

最新资料更新

  • 1.网页php查看源代码 php怎么看源码
  • 2.phpmp3播放 php播放器本地视频
  • 3.php编写确认密码 php用户名密码
  • 4.关于php_ssh.dll的信息
  • 5.php解压gz效率 rarphp文件怎么解压
  • 6.php构造方法重写 php 构造方法
  • 7.phpsessions phpsession使用
  • 8.php获取阴历 php获取日期
  • 9.php浏览页面乱码 php页面字符出现乱码怎么解决
  • 10.php提取css文件 php引用css文件
  • 11.php短信被刷 php防止短信被刷
  • 12.字符串对齐方法php php字符串赋值
  • 13.关于winformphp的信息
  • 14.包含php-fpm-t的词条
  • 15.文章加载更多php php加载html
  • 16.php循环处理速度 phpforeach循环
  • 17.包含asp和php互通的词条
  • 18.php变下载文件 php 下载文件
  • 19.红帽升级php 红帽linux最新版
  • 20.JavaPHP你好 java welcome

CopyRight:2016-{hedonghua:year}{hedonghua:sitegs} 备案ICP:湘ICP备09009000号-16 {hedonghua:sitejym}
本站资讯不构成任何建议,仅限于个人分享,参考须谨慎!
本网站对有关资料所引致的错误、不确或遗漏,概不负任何法律责任。
本网站刊载的所有内容(包括但不仅限文字、图片、LOGO、音频、视频、软件、程序等)版权归原作者所有。任何单位或个人认为本网站中的内容可能涉嫌侵犯其知识产权或存在不实内容时,请及时通知本站,予以删除。

网站内容来源于网络分享,如有侵权发邮箱到:kenbest@126.com,收到邮件我们会即时下线处理。
网站框架支持:HDHCMS   51LA统计 百度统计
Copyright © 2018-2026 「好得很程序员自学网」
[ SiteMap ]