当前位置:网站首页>PHP mnemonic code full text 400 words to extract the first letter of each Chinese character
PHP mnemonic code full text 400 words to extract the first letter of each Chinese character
2022-07-03 08:46:00 【The luckier~】
Mnemonic code : similar ,
Xiao Ming ------XM ,
Xiaohong -------XH,
Xiaoyun ------XY,
The following is the code implementation :
<?php
// Definition
$str = ' I am a good person ';
function mbstringtoarray($str, $charset)
{
$strlen = mb_strlen($str);
while ($strlen) {
$array[] = mb_substr($str, 0, 1, $charset);
$str = mb_substr($str, 1, $strlen, $charset);
$strlen = mb_strlen($str);
}
return $array;
}
$arr = mbstringtoarray($str, "utf-8");
//print_r($arr);
// You can get the first letter of the first word of a sentence
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;
}
// Test functions getFirstCharter Output result
//echo getFirstCharter($str);
foreach ($arr as $k => &$v) {
echo $v = getFirstCharter($v);
}
边栏推荐
- Cloudcompare learning (1) - cloudcompare compilation and common plug-in implementation
- MySQL index types B-tree and hash
- Jupyter remote server configuration and server startup
- Unity editor expansion - draw lines
- Introduction to hexadecimal coding
- [concurrent programming] Table hopping and blocking queue
- Advanced OSG collision detection
- 注解简化配置与启动时加载
- [concurrent programming] collaboration between threads
- Location of package cache downloaded by unity packagemanager
猜你喜欢
![[concurrent programming] thread foundation and sharing between threads](/img/26/60fbfe65b186867a3b1cb58d481226.jpg)
[concurrent programming] thread foundation and sharing between threads

ES6 promise learning notes

Graphics_ Games101/202 learning notes

Redux - learning notes

Notes on understanding applets 2022/7/3
![[redis] redis persistent RDB vs AOF (source code)](/img/57/b6a86c49cedee31fc00dc5d1372023.jpg)
[redis] redis persistent RDB vs AOF (source code)

Message queue for interprocess communication

Simply start with the essence and principle of SOM neural network

Creation of osgearth earth files to the earth ------ osgearth rendering engine series (1)

Monotonic stack -42 Connect rainwater
随机推荐
Unity editor expansion - the design idea of imgui
[cloud native] introduction and use of feign of microservices
Thymeleaf 404 reports an error: there was unexpected error (type=not found, status=404)
C language student management system based on linked list, super detailed
php-fpm软件的安装+openresty高速缓存搭建
UE4 source code reading_ Bone model and animation system_ Animation process
Constraintlayout's constraintset dynamically modifies constraints
梯度下降法求解BP神经网络的简单Demo
Dom4j遍历和更新XML
Deep parsing JVM memory model
[concurrent programming] collaboration between threads
基于SSM的校园失物招领平台,源码,数据库脚本,项目导入运行视频教程,论文撰写教程
Graphics_ Learnopongl learning notes
Sending and receiving of request parameters
22-06-27 西安 redis(01) 安装redis、redis5种常见数据类型的命令
Cloudcompare learning (1) - cloudcompare compilation and common plug-in implementation
Development experience and experience
ES6 promise learning notes
单调栈-42. 接雨水
Unity interactive water ripple post-treatment