如何检测并删除重复的内容,忽略重复的"\n"
- 用PHP?
我有以下字符串:
\ nrazor989 \ nalcatraz \ nartez \ ntajemniczyxd \ nmrrazor \ nqwertyuiop \ npomroczny4 \ nomgdmg \ ngreat_jojek \ nmaciekcz242 \ nkaka2610 \ nteleskop1 \ nsupciokawa \ nklocek18 \ nkacpi999 \ npawel1909 \ npozbierany \ nkelthuzan \ nistrim \ ngroch \ nmario \ nalcatraz \ n < / p>
答案 0 :(得分:3)
请尝试
$str = 'your string';
$ar = explode('\n', $str);
$ar = array_unique($ar);
echo implode('\n', $ar); //edited - original code had $arr
答案 1 :(得分:2)
使其成为一个独特的阵列:
$massiveString = '\nrazor989\nalcatraz\nartez\ntajemniczyxd\nmrrazor\nqwertyuiop\npomroczny4\nomgdmg\ngreat_jojek\nmaciekcz242\nkaka2610\nteleskop1\nsupciokawa\nklocek18\nkacpi999\npawel1909\npozbierany\nkelthuzan\nistrim\ngroch\nmario\nalcatraz\n';
echo implode('\n', array_unique(explode('\n', $massiveString)));