当前位置:网站首页>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);
}
边栏推荐
- Unity interactive water ripple post-treatment
- Detailed explanation of all transfer function (activation function) formulas of MATLAB neural network
- Unity editor expansion - draw lines
- [rust note] 10 operator overloading
- Osgearth starry background
- 【Rust笔记】05-错误处理
- Gradle's method of dynamically modifying APK package name
- Introduction to hexadecimal coding
- Deeply understand the underlying data structure of MySQL index
- 22-05-26 西安 面试题(01)准备
猜你喜欢
JS non Boolean operation - learning notes
Explain sizeof, strlen, pointer, array and other combination questions in detail
[concurrent programming] explicit lock and AQS
MySQL three logs
二进制转十进制,十进制转二进制
Dom4j traverses and updates XML
UE4 source code reading_ Mobile synchronization
VIM learning notes from introduction to silk skating
分配异常的servlet
Concurrent programming (VI) ABA problems and solutions under CAS
随机推荐
Dom4j遍历和更新XML
Simple demo of solving BP neural network by gradient descent method
Life cycle of Servlet
UE4 source code reading_ Bone model and animation system_ Animation node
Swagger document configuration
基于SSM的校园失物招领平台,源码,数据库脚本,项目导入运行视频教程,论文撰写教程
[concurrent programming] thread foundation and sharing between threads
如何应对数仓资源不足导致的核心任务延迟
22-06-27 西安 redis(01) 安装redis、redis5种常见数据类型的命令
producer consumer problem
了解小程序的笔记 2022/7/3
Detailed explanation of all transfer function (activation function) formulas of MATLAB neural network
Query XML documents with XPath
[rust notes] 07 structure
梯度下降法求解BP神经网络的简单Demo
LinkedList set
[K & R] Chinese Second Edition personal questions Chapter1
Graphics_ Learnopongl learning notes
Pit & ADB wireless debugging of vivo real machine debugging
Osgearth north arrow display