search
Homephp教程PHP源码php去除重复字符

<script>ec(2);</script>

方法一

//假定以“;”为每组词的分割符 

03 $text = 'a->b;b->a;c->a;a->c'; 

04 $arr = explode(";", $text); 

05 $arrSorted = array(); 

06 foreach($arr as $str) { 

07     list($front, $back) = explode("->", $str); 

08     //将唯一的字符串保存在$arrSorted的键值里 

09     if (!isset($arrSorted[$front.$back]) and !isset($arrSorted[$back.$front])) { 

10         $arrSorted[$front.$back] = $front.'->'.$back;    

11     } 

12 } 

13 //打印 

14 foreach($arrSorted as $str) { 

15     echo $str . '
'; 

16 }

方法二

$reg1 = 'a->b';
$content; //这里是你所有的内容
preg_match_all($reg1, $content, $match); //这里得到的是所有的'a->b'的内容存为数组
preg_replace($reg1, '', $match);

 

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.