php对UTF8字体串进行单字分割返回数组
在网上查了很多字符串分割方法,都无法正确对UTF8字符串进行正确分割返回单个字符的数组。经过对FTU8编码的分析写出了下面的方法对UTF8进行分割。本人测试可用。本方法只支持UTF8编码的,其它编码转自行转换成UT8再使用。
$tempaddtext="http://www.jishubu.net php对UTF8字体串进行单字分割返回数组";
//$tempaddtext=iconv("GBK","UTF-8",$tempaddtext); //字符编码转换,自行判定需要不需要
$cind = 0;
$arr_cont = array();
for ($i = 0; $i < strlen($tempaddtext); $i++) {
if (strlen(substr($tempaddtext, $cind, 1)) > 0) {
if (ord(substr($tempaddtext, $cind, 1)) < 192) {
if (substr($tempaddtext, $cind, 1) != " ") {
array_push($arr_cont, substr($tempaddtext, $cind, 1));
}
$cind++;
} elseif(ord(substr($tempaddtext, $cind, 1)) < 224) {
array_push($arr_cont, substr($tempaddtext, $cind, 2));
$cind+=2;
} else {
array_push($arr_cont, substr($tempaddtext, $cind, 3));
$cind+=3;
}
}
} print_r($arr_cont);
返回结果:
Array ( [0] => h [1] => t [2] => t [3] => p [4] => : [5] => / [6] => / [7] => w [8] => w [9] => w [10] => . [11] => j [12] => i [13] => s [14] => h [15] => u [16] => b [17] => u [18] => . [19] => n [20] => e [21] => t [22] => p [23] => h [24] => p [25] => 对 [26] => U [27] => T [28] => F [29] => 8 [30] => 字 [31] => 体 [32] => 串 [33] => 进 [34] => 行 [35] => 单 [36] => 字 [37] => 分 [38] => 割 [39] => 返 [40] => 回 [41] => 数 [42] => 组 )
php对UTF8字体串进行单字分割返回数组的更多相关文章
- [Google Guava] 6-字符串处理:分割,连接,填充
原文链接 译文链接 译者:沈义扬,校对:丁一 连接器[Joiner] 用分隔符把字符串序列连接起来也可能会遇上不必要的麻烦.如果字符串序列中含有null,那连接操作会更难.Fluent风格的Joine ...
- c#调用dll接口传递utf-8字串方法
1. 起源: VCU10之视频下载模块,采用纯python编码实现,c++代码调用pythonrun.h配置python运行环境启动python模块,编译为dll给c#调用,以使界面UI能够使用其中功 ...
- oracle根据分隔符将字符串分割成数组函数
--创建表类型 create or replace type mytype as table of number;--如果定义成varchar--CREATE OR REPLACE type myty ...
- 第4章学习小结_串(BF&KMP算法)、数组(三元组)
这一章学习之后,我想对串这个部分写一下我的总结体会. 串也有顺序和链式两种存储结构,但大多采用顺序存储结构比较方便.字符串定义可以用字符数组比如:char c[10];也可以用C++中定义一个字符串s ...
- 将中文字符串分割为数组 解决str_split中文乱码php
首先来介绍str_split()这个函数: 它的作用是将字符串分割为数组: 例如: $str='abcde';str_plite($str); 打印结果如下:Array( [0] => a ...
- Linux shell 将字符串分割成数组
原文链接:http://1985wanggang.blog.163.com/blog/static/776383320121745626320/ a="one,two,three,four& ...
- js实现把textarea通过换行或者回车把多行数字分割成数组,并且去掉数组中空的值。
删除数组指定的某个元素 var msg = " "; //textarea 文本框输入的内容 var emp = [ ]; //定义一个数组,用来存msg分割好的内容 1. ...
- [转+整理]linux shell 将字符串分割成数组
原文链接:http://1985wanggang.blog.163.com/blog/static/776383320121745626320/ a="one,two,three,four& ...
- JS中,split()用法(将字符串按指定符号分割成数组)
<!DOCTYPE html> <html> <head> <meta charset="{CHARSET}"> <title ...
随机推荐
- hadoop2.1.0和hadoop2.2.0编译安装教程
由于现在hadoop2.0还处于beta版本,在apache官方网站上发布的beta版本中只有编译好的32bit可用,如果你直接下载安装在64bit的linux系统的机器上,运行会报一个INFO ut ...
- AJAX顺序输出
转载:http://www.cnblogs.com/niunan/archive/2010/10/13/1849873.html AJAX顺序输出 在安装大多数CMS的时候都会在安装界面上看到这样的 ...
- Hdu 5568 sequence2 高精度 dp
sequence2 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=556 ...
- delphi array应用 DayOfWeek星期几判断
//array应用 DayOfWeek星期几判断 procedure TForm1.Button1Click(Sender: TObject);var days:array[1..7] of s ...
- Ubuntu下多服务器 Rsync同步镜像服务配置
主服务器:192.168.5.13_ubuntu 从服务器:192.168.5.11_centos ================== 1> 在两台主机上分别安装rsync========== ...
- mongo批量更新
update的如果要批量更新是无能为力的,如果有多条匹配的结果,但结果是只能更新一条. 用bulk来进行处理 var bulk = db.HIS_ALARM.initializeUnorderedBu ...
- [Angular 2] Factory Provider
In this lesson, we discuss how and when to use factory providers, to enable dependencies that should ...
- Swift常用语法示例代码(一)
此篇文章整理自我以前学习Swift时的一些练习代码,其存在的意义多是可以通过看示例代码更快地回忆Swift的主要语法. 如果你想系统学习Swift或者是Swift的初学者请绕路,感谢Github上Th ...
- CODEFORCE 246 Div.2 B题
题目例如以下: B. Football Kit time limit per test 1 second memory limit per test 256 megabytes input stand ...
- XtraBackup原理5
http://www.cnblogs.com/gomysql/p/3650645.html xtrabackup是Percona公司CTO Vadim参与开发的一款基于InnoDB的在线热备工具,具有 ...