php去除重复字的实现代码

来源:互联网 发布:c语言编写库文件 编辑:程序博客网 时间:2024/06/05 09:38
php去除重复字的实现代码,需要的朋友可以参考下。
方法一:
<?php//去除数组中重复字$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;}} //by www.jbxue.comecho $text_filter;

方法二:
<?php//去除重复字//by www.jbxue.com$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()这个函数。 

原创粉丝点击