php去除重复字符
方法一
<?php //假定以“;”为每组词的分割符 $text = 'a->b;b->a;c->a;a->c'; $arr = explode(";", $text); $arrSorted = array(); foreach($arr as $str) { list($front, $back) = explode("->", $str); //将唯一的字符串保存在$arrSorted的键值里 if (!isset($arrSorted[$front.$back]) and !isset($arrSorted[$back.$front])) { $arrSorted[$front.$back] = $front.'->'.$back; } } //打印 foreach($arrSorted as $str) { echo $str . '<br/>'; }
方法二
<?php $reg1 = 'a->b'; $content; //这里是你所有的内容 preg_match_all($reg1, $content, $match); //这里得到的是所有的'a->b'的内容存为数组 preg_replace($reg1, '', $match);
本文地址:http://www.phprm.com/code/899e11a21ae817a97d3ce64f851ab9f6.html
转载随意,但请附上文章地址:-)