php 去掉重复字,php去除重复字的实现代码

$text = ‘数组aabbccdd‘;

$text_filter = ‘‘;

$filter = array();

$len = mb_strlen($text, ‘utf-8‘);

for ($i = 0; $i

$char = mb_substr($text, $i, 1, ‘utf-8‘);

if (!isset($filter[$char])) {

$text_filter .= $char;

$filter[$char] = $char;

}

}

echo $text_filter;

方法二:

$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()这个函数。

原文:http://www.jb51.net/article/28310.htm

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值