当前位置:网站首页>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);
}
边栏推荐
- Creation and content of mapnode -- osgearth rendering engine series (2)
- Find the intersection of line segments
- Transmit pictures with Base64 encoding
- 【Rust 笔记】11-实用特型
- Osgearth north arrow display
- Sequence of map implementation classes
- 100 GIS practical application cases (78) - Multi compliance database design and data warehousing
- Message queue for interprocess communication
- 如何应对数仓资源不足导致的核心任务延迟
- Deep parsing JVM memory model
猜你喜欢

Binary to decimal, decimal to binary

Redux - learning notes

Unity learning notes

Final review of Database Principles

Deep parsing (picture and text) JVM garbage collector (II)

Data analysis exercises

Sending and receiving of request parameters

UE4 source code reading_ Bone model and animation system_ Animation node

Simple demo of solving BP neural network by gradient descent method

Log4j2 vulnerability recurrence and analysis
随机推荐
First Servlet
Alibaba canaladmin deployment and canal cluster Ha Construction
Redis data structure
MySQL containerization (1) docker installation MySQL
Unity Editor Extension - drag and drop
How does unity fixedupdate call at a fixed frame rate
Unity Editor Extension - event handling
100 GIS practical application cases (78) - Multi compliance database design and data warehousing
redis集群系列四
[rust notes] 08 enumeration and mode
【Rust 笔记】13-迭代器(上)
Introduction to Base64 coding
[redis] redis persistent RDB vs AOF (source code)
Unity editor expansion - draw lines
22-05-26 西安 面试题(01)准备
ES6 promise learning notes
[MySQL] MySQL Performance Optimization Practice: introduction of database lock and index search principle
Allocation exception Servlet
796 · unlock
Thymeleaf 404 reports an error: there was unexpected error (type=not found, status=404)