Home > Backend Development > PHP Tutorial > php去除重复字的实现代码_PHP

php去除重复字的实现代码_PHP

WBOY
Release: 2016-06-01 12:14:28
Original
940 people have browsed it

方法一:
复制代码 代码如下:
$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 $value = ord($str[$i]);
if($value > 127){
if($value >= 192 && $value $split=2;
elseif($value >= 224 && $value $split=3;
elseif($value >= 240 && $value $split=4;
}else{
$split=1;
}
$key = NULL;
for ( $j = 0; $j $key .= $str[$i];
}
array_push( $array, $key );
}
return $array;
}
print_r(array_unique(str_split_utf8($string)));

方法三:

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template