当前位置:网站首页>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 notes 1
- Explain sizeof, strlen, pointer, array and other combination questions in detail
- Unity Editor Extension - event handling
- [concurrent programming] concurrent tool class of thread
- [rust notes] 08 enumeration and mode
- 22-06-28 西安 redis(02) 持久化机制、入门使用、事务控制、主从复制机制
- URL backup 1
- Unity editor expansion - scrolling list
- [concurrent programming] collaboration between threads
- 了解小程序的笔记 2022/7/3
猜你喜欢

Cloudcompare learning (1) - cloudcompare compilation and common plug-in implementation

UE4 source code reading_ Bone model and animation system_ Animation process

Chocolate installation

Installation of PHP FPM software +openresty cache construction

Image processing 8-cnn image classification
![[concurrent programming] explicit lock and AQS](/img/5f/a80751a68726f53d11133810f454a3.jpg)
[concurrent programming] explicit lock and AQS

Display terrain database on osgearth ball
![[concurrent programming] concurrent tool class of thread](/img/16/2b4d2b3528b138304a1a3918773ecf.jpg)
[concurrent programming] concurrent tool class of thread

梯度下降法求解BP神经网络的简单Demo
![[rust notes] 02 ownership](/img/f7/74f8ea3bd697957f9ebfa3e1513fda.png)
[rust notes] 02 ownership
随机推荐
Development experience and experience
UE4 source code reading_ Bone model and animation system_ Animation compression
单调栈-84. 柱状图中最大的矩形
详解sizeof、strlen、指针和数组等组合题
Allocation exception Servlet
[rust notes] 09- special types and generics
[concurrent programming] explicit lock and AQS
First Servlet
MySQL index types B-tree and hash
Image processing 8-cnn image classification
Chocolate installation
Query XML documents with XPath
Servlet的生命周期
[concurrent programming] synchronization container, concurrent container, blocking queue, double ended queue and work secret
Collection interface
【Rust笔记】06-包和模块
[redis] redis persistent RDB vs AOF (source code)
22-06-27 西安 redis(01) 安装redis、redis5种常见数据类型的命令
使用base64编码传图片
22-06-28 Xi'an redis (02) persistence mechanism, entry, transaction control, master-slave replication mechanism