加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php去除重复字的实现代码

发布时间:2020-12-13 05:59:50 所属栏目:PHP教程 来源:网络整理
导读:方法一: div class="codetitle" a style="CURSOR: pointer" data="58604" class="copybut" id="copybut58604" onclick="doCopy('code58604')" 代码如下: div class="codebody" id="code58604" $text = '数组aabbccdd'; $text_filter = ''; $filter = array(

方法一:
<div class="codetitle"><a style="CURSOR: pointer" data="58604" class="copybut" id="copybut58604" onclick="doCopy('code58604')"> 代码如下:<div class="codebody" id="code58604">
$text = '数组aabbccdd';
$text_filter = '';
$filter = array();
$len = mb_strlen($text,'utf-8');
for ($i = 0; $i<$len; $i++) {
$char = mb_substr($text,$i,1,'utf-8');
if (!isset($filter[$char])) {
$text_filter .= $char;
$filter[$char] = $char;
}
}
echo $text_filter;

方法二:
<div class="codetitle"><a style="CURSOR: pointer" data="50318" class="copybut" id="copybut50318" onclick="doCopy('code50318')"> 代码如下:<div class="codebody" id="code50318">
$string= '数组aabbccdd';
function str_split_utf8($str) {
$split=1;
$array = array();
for ( $i=0; $i < strlen( $str ); ){
$value = ord($str[$i]);
if($value > 127){
if($value >= 192 && $value <= 223)
$split=2;
elseif($value >= 224 && $value <= 239)
$split=3;
elseif($value >= 240 && $value <= 247)
$split=4;
}else{
$split=1;
}
$key = NULL;
for ( $j = 0; $j < $split; $j++,$i++ ) {
$key .= $str[$i];
}
array_push( $array,$key );
}
return $array;
}
print_r(array_unique(str_split_utf8($string)));

方法三: 就是把每一个字分割在数组里再用array_unique()这个函数。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读