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 ...
随机推荐
- JS 的点点滴滴
1. ||含义 : 返回第一个有效值 eg : <script type="text/javascript"> var a=""; var c = ...
- AndroidCharts为折线图表添加y坐标
AndroidCharts 是一款轻量级的图表显示控件,对比起Android-Charts和AChartEngine来说简单和活泼了很多,适合数据展示不需要太过详细专业的场合,它支持简单且带动画的折线 ...
- squid添加用户名密码认证
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html 内部邀请码:C8E245J (不写邀请码,没有现金送) 国 ...
- Codeforces Bubble Cup 8 - Finals [Online Mirror] D. Tablecity 数学题
D. Tablecity Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/575/problem/D ...
- delphi 插入表格HTML代码
<table width="174" height="76" border="1" align="center" ...
- [AngularJS] New in Angular 1.3 - Performance Boost with debugInfoEnabled
By default, Angular provides a lot of debug information on the DOM that's only necessary for tools l ...
- oc-03-OC访问OC源文件、C源文件中的函数
show.h #ifndef __OCDay01__Show__ #define __OCDay01__Show__ #include <stdio.h> extern void test ...
- int a[5]={}, &a+1与(int*)a+1的区别
#include <iostream> #include <typeinfo> using namespace std; int main() { int b, *pb; ch ...
- qt 获取系统磁盘空间大小
quint64 getDiskFreeSpace(QString driver) { LPCWSTR lpcwstrDriver=(LPCWSTR)driver.utf16(); ULARGE_INT ...
- DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements SingletonBeanRegistry
// 用于内部标记的空的单例对象(不支持null)protected static final Object NULL_OBJECT = new Object(); // 缓存单例对象根据beanNa ...