在网上查了很多字符串分割方法,都无法正确对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字体串进行单字分割返回数组的更多相关文章

  1. [Google Guava] 6-字符串处理:分割,连接,填充

    原文链接 译文链接 译者:沈义扬,校对:丁一 连接器[Joiner] 用分隔符把字符串序列连接起来也可能会遇上不必要的麻烦.如果字符串序列中含有null,那连接操作会更难.Fluent风格的Joine ...

  2. c#调用dll接口传递utf-8字串方法

    1. 起源: VCU10之视频下载模块,采用纯python编码实现,c++代码调用pythonrun.h配置python运行环境启动python模块,编译为dll给c#调用,以使界面UI能够使用其中功 ...

  3. oracle根据分隔符将字符串分割成数组函数

    --创建表类型 create or replace type mytype as table of number;--如果定义成varchar--CREATE OR REPLACE type myty ...

  4. 第4章学习小结_串(BF&KMP算法)、数组(三元组)

    这一章学习之后,我想对串这个部分写一下我的总结体会. 串也有顺序和链式两种存储结构,但大多采用顺序存储结构比较方便.字符串定义可以用字符数组比如:char c[10];也可以用C++中定义一个字符串s ...

  5. 将中文字符串分割为数组 解决str_split中文乱码php

    首先来介绍str_split()这个函数: 它的作用是将字符串分割为数组: 例如: $str='abcde';str_plite($str); 打印结果如下:Array(    [0] => a ...

  6. Linux shell 将字符串分割成数组

    原文链接:http://1985wanggang.blog.163.com/blog/static/776383320121745626320/ a="one,two,three,four& ...

  7. js实现把textarea通过换行或者回车把多行数字分割成数组,并且去掉数组中空的值。

    删除数组指定的某个元素 var msg = " ";  //textarea  文本框输入的内容 var emp = [ ];   //定义一个数组,用来存msg分割好的内容 1. ...

  8. [转+整理]linux shell 将字符串分割成数组

    原文链接:http://1985wanggang.blog.163.com/blog/static/776383320121745626320/ a="one,two,three,four& ...

  9. JS中,split()用法(将字符串按指定符号分割成数组)

    <!DOCTYPE html> <html> <head> <meta charset="{CHARSET}"> <title ...

随机推荐

  1. php+gd库的源码安装

    php+gd库的源码安装     PHP+GD安装   一.下载软件 gd-2.0.35.tar.gz          http://www.boutell.com/gd/ jpegsrc.v6b. ...

  2. C语言signal处理的小例子

    [pgsql@localhost tst]$ cat sig01.c #include <stdio.h> #include <signal.h> static void tr ...

  3. TChromeTabs 使用日记

    1.如何让 Tab 在拖放时,拖放图形中带有 TabControl 的内容. 增加 ChromeTabs 的 NeedDragImageControl 事件,并在代码中设置 DragControl 为 ...

  4. 数据返回[数据库基础]——图解JOIN

    废话就不多说了,开始... 一.提要 JOIN对于接触过数据库的人,这个词都不生疏,而且很多人很清楚各种JOIN,还有很多人对这个懂得也不是很透辟,此次就说说JOIN操纵. 图片是很容易被接受和懂得, ...

  5. bzoj 4300: 绝世好题 dp

    4300: 绝世好题 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/problem.php ...

  6. 2015南阳CCPC D - Pick The Sticks dp

    D - Pick The Sticks Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description The story happened lon ...

  7. URAL 1775 B - Space Bowling 计算几何

    B - Space BowlingTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...

  8. [AngularJS] ngModelController render function

    ModelValue and ViewValue: $viewValue: Actual string value in the view. $modelValue: The value in the ...

  9. pthread实现多线程查询(转)

    导读:大多数网站的性能瓶颈不在PHP服务器上,因为它可以简单地通过横向增加服务器或CPU核数来轻松应对(对于各种云主机,增加VPS或CPU核数就更方便了,直接以备份镜像增加VPS,连操作系统.环境都不 ...

  10. MySQL · BUG分析 · Rename table 死锁分析

    http://mysql.taobao.org/monthly/2016/03/06/ 背景 InnoDB buffer pool中的page管理牵涉到两个链表,一个是lru链表,一个是flush 脏 ...