删除字符串中所有重复的字符? [英] Remove all duplicate characters in a string?

查看:97
本文介绍了删除字符串中所有重复的字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有以下内容:

$str = "1AAABBCCCDDDDDDD";

如何删除字符串中所有重复的字符?这样看起来像这样吗?

How can I remove all the duplicate characters in the string? So it would look like this?

$result = "1ABCD";

推荐答案

所有您需要的是 count_chars() :

All you need is count_chars():

$result = count_chars( $str, 3);

在第二个参数$mode设置为3的情况下,count_chars()将输出:

With the second parameter $mode set to 3, count_chars() will output:

包含所有唯一字符的字符串

a string containing all unique characters

您可以从此演示中看到以下内容:

You can see from this demo that this produces:

1ABCD

这篇关于删除字符串中所有重复的字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆