Analysing a string, probably using a regex
Posted: Sun Apr 06, 2008 6:53 am
Hi everyone
I have a string, that I want to analyse and load into an array. The string looks something like this:
And I want the result looking something like this:
The result does not have to be exactly like this, I just need to see the structure of the original string. Also note that the input has an undefinded number of entries, so the result may be an array with three items like in the example above, but may also contain several hundered items..
I know that this can be done some loops in combination with strpos, but I don't like this approach. Does anyone have a cool idea how to do this job in a smart, and primarily fast way? I guess some regex magic could be used, but I don't know how at the moment.
I have a string, that I want to analyse and load into an array. The string looks something like this:
Code: Select all
"<something>[blah][dkl][ilow]<somestring>[fdskl][iloveu]<anotherone>[dfsk]"Code: Select all
Array
(
['something'] => Array
(
[0] => blah
[1] => dkl
[2] => ilow
)
['somestring'] => Array
(
[0] => fdskl
[1] => iloveu
)
['anotherone'] => Array
(
[0] => dfsk
)
)I know that this can be done some loops in combination with strpos, but I don't like this approach. Does anyone have a cool idea how to do this job in a smart, and primarily fast way? I guess some regex magic could be used, but I don't know how at the moment.