当前位置:网站首页>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 editor expansion - controls, layouts
- Intersectionpicker in osgearth
- [rust notes] 02 ownership
- Unity learning notes
- Deep parsing (picture and text) JVM garbage collector (II)
- [concurrent programming] synchronization container, concurrent container, blocking queue, double ended queue and work secret
- [MySQL] MySQL Performance Optimization Practice: introduction of database lock and index search principle
- Constraintlayout's constraintset dynamically modifies constraints
- Binary to decimal, decimal to binary
- 22-06-27 Xian redis (01) commands for installing five common data types: redis and redis
猜你喜欢
Solution détaillée de toutes les formules de fonction de transfert (fonction d'activation) du réseau neuronal MATLAB
Graphics_ Games101/202 learning notes
Animation_ IK overview
Markdown learning
Log4j2 vulnerability recurrence and analysis
Final review of Database Principles
[concurrent programming] Table hopping and blocking queue
数据库原理期末复习
Jupyter remote server configuration and server startup
GIS实战应用案例100篇(七十八)-多规合一数据库设计及数据入库
随机推荐
[set theory] order relation (total order relation | total order set | total order relation example | quasi order relation | quasi order relation theorem | bifurcation | quasi linear order relation | q
Development material set
Unity learning notes
Analysis of Alibaba canal principle
[concurrent programming] collaboration between threads
二进制转十进制,十进制转二进制
Graphics_ Games101/202 learning notes
Monotonic stack -503 Next bigger Element II
Concurrent programming (V) detailed explanation of atomic and unsafe magic classes
Unity editor expansion - controls, layouts
Dom4j遍历和更新XML
[rust notes] 09- special types and generics
Notes on understanding applets 2022/7/3
Osgearth north arrow display
Unity multi open script
Talking about: is the HashSet set ordered or disordered /hashset set unique, why can we store elements with the same content
Final review of Database Principles
[linear table] basic operation of bidirectional linked list specify node exchange
LinkedList set
Markdown learning