当前位置:网站首页>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);
}
边栏推荐
- 【Rust 笔记】09-特型与泛型
- 了解小程序的笔记 2022/7/3
- Explain sizeof, strlen, pointer, array and other combination questions in detail
- Creation and content of mapnode -- osgearth rendering engine series (2)
- 【Rust 笔记】08-枚举与模式
- Cesium service deployment, and import and display local 3dfiles data
- Analysis of Alibaba canal principle
- Notes on understanding applets 2022/7/3
- [rust notes] 02 ownership
- 【Rust 笔记】12-闭包
猜你喜欢

梯度下降法求解BP神经网络的简单Demo

Unity editor expansion - scrolling list

Graphics_ Games101/202 learning notes

Life cycle of Servlet

Unity learning notes
![[concurrent programming] thread foundation and sharing between threads](/img/26/60fbfe65b186867a3b1cb58d481226.jpg)
[concurrent programming] thread foundation and sharing between threads

单调栈-42. 接雨水

Data analysis exercises

VIM learning notes from introduction to silk skating
![[RPC] RPC remote procedure call](/img/dc/872204ea47fcff04cdb72e18a2a4ef.jpg)
[RPC] RPC remote procedure call
随机推荐
Markdown directory generation
Osgconv tool usage
matlab神經網絡所有傳遞函數(激活函數)公式詳解
Simple demo of solving BP neural network by gradient descent method
Unity editor expansion - the design idea of imgui
Allocation exception Servlet
Drawing maze EasyX library with recursive backtracking method
Collection interface
MySQL three logs
Constraintlayout's constraintset dynamically modifies constraints
[MySQL] MySQL Performance Optimization Practice: introduction of database lock and index search principle
Display terrain database on osgearth ball
Cesium for unreal quick start - simple scenario configuration
First Servlet
Dealing with duplicate data in Excel with xlwings
Unity interactive water ripple post-treatment
Sending and receiving of request parameters
[updating] wechat applet learning notes_ three
Servlet的生命周期
Chocolate installation