Php implementation code for removing duplicate words

Source: Internet
Author: User

Method 1:
Copy codeThe Code is as follows:
$ Text = 'array 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;

Method 2:
Copy codeThe Code is as follows:
$ String = 'array aabbccdd ';
Function str_split_utf8 ($ str ){
$ Split = 1;
$ Array = array ();
For ($ I = 0; $ I <strlen ($ str );){
$ Value = ord ($ str [$ I]);
If ($ value & gt; 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 )));

Method 3:

The array_unique () function is used to separate each word into an array.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.