Ec (2); Method 1 assumes that & ldquo; & rdquo; is the separator for each group of words & nbsp; 03 $ texta-& gt; B-& gt; a; c-& gt; a-& gt; c; & nbsp; 04 $ arrexplode (& quot;, $ text); & nbsp; 05 $ arrSortedarray (); & nbsp; 06 foreach ($ arras $ script ec (2); script
Method 1
// Assume that ";" is the delimiter of each group of words.
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 // Save the unique string in the key value of $ arrSorted
09 if (! Isset ($ arrSorted [$ front. $ back]) and! Isset ($ arrSorted [$ back. $ front]) {
10 $ arrSorted [$ front. $ back] = $ front. '->'. $ back;
11}
12}
13 // print
14 foreach ($ arrSorted as $ str ){
15 echo $ str .'
';
16}
Method 2
$ Reg1 = 'a-> B ';
$ Content; // all your content here
Preg_match_all ($ reg1, $ content, $ match); // All 'a-> B 'contents are saved as arrays.
Preg_replace ($ reg1, '', $ match );