Hi,
I have a question about sorting the content of a string.
I have a string that contains coordinates ...
it looks like this:
Code:
"[aa][bc][sa][dd][qq][se][zd][dk][ks]"
each coordinate looks like this:
This string needs to be sorted so that I get the following result:
Code:
"[aa][bc][dd][dk][ks][sa][se][qq][zd]"
What is the best way to do this?
I was thinking to do it the following way:
First I would parse all coordinates by using a for-loop and the substr function. And I would put them in an array. Next I would sort the array with the sort() function.
So after the sorting the array would look like this:
Code:
aa
bc
dd
dk
ks
sa
se
qq
zd
I was just thinking... Is there a faster way?
I saw somebody solving a simular problem by using regular expressions:
Code:
$list = preg_split('/;\s*/', $str);
The problem is: I forgot how to create regular expressions. I was just wondering, is there somebody who can spare me 2 hours of reading, studying and testing and give me the pattern
. That would be very nice!
Thank you very much in advance !