Originally posted by ppowell
Ok I know that much of preg_match_all, but that's as far as I can go. I don't understand the constants nor how the 2-dim array is set. Basically, I just plain don't know how to use it.
Phil
Oh, okay.
Well, if you know how the array is set for preg_match(), you're a third of the way there.
The default arrangement for the two-dimensional array is a list of arrays the same as what preg_match() would give you if you could apply it repeatedly:
[ [1st matched string] [1st paren'd substring in 1st match] [2nd paren'd substring in 1st match] ...]
[ [2nd matched string] [1st paren'd substring in 2nd match] [2nd paren'd substring in 2nd match] ...]
[ [3rd matched string] [1st paren'd substring in 3rd match] [2rd paren'd substring in 3rd match] ...]
...
]
PREG_SET_ORDER gives the transpose of that array
[ [1st matched string] [2nd matched string] [3rd matched string] ...]
[ [1st paren'd substring in 1st match] [1st paren'd substring in 2nd match] [1st paren'd substring in 3rd match] ...]
[ [2rd paren'd substring in 1rd match] [2rd paren'd substring in 2rd match] [2rd paren'd substring in 3rd match] ...]
...
]
PREG_OFFSET_CAPTURE replaces each element in the two-dimensional array with an array, (making it a three-dimensional array), where the 0th element is the same as above, and the 1st element is the position that that substring appears in the original string.
Try playing around with the second example on the [man]preg_match_all[/man] page, setting various combinations of flags, and print_r the resulting $matches array.