Hi,
I have to decode a string, which contains some repeating elements and continues as a generic text. Example:
OCT 28 29 NOV 03 04 05 10 11 DAILY 0800-SS NOV 15 18 23 DAILY SR-SS NOV 24 26 0700-1500 blablabla blabla
output should be an array like
[0][0] = {OCT,28,29,NOV,03,04,05,10,11} // month and days
[0][1] = {0800,SS} // start and end data - SS = sunset, SR = sunrise
[1][0] = {NOV,15,18,23}
[1][1] = {SR,SS}
[2][0] = {NOV,24,26}
[2]10] = {0700,1500}
I am not able to construct such a patern. Please, could anybody help me?
M.
Repeating paterns within paterns
Moderator: General Moderators
Code: Select all
preg_match_all('/
# month and days
(
(?:
[A-Y]{3}\s
(?:\d{2}\s)+
)+
)
(?:DAILY\s)?
# sunrise and sunset
(
(?:\d{4}|SR)
-
(?:\d{4}|SS)
)
/x',
'OCT 28 29 NOV 03 04 05 10 11 DAILY 0800-SS NOV 15 18 23 DAILY SR-SS NOV 24 26 0700-1500',
$matches);Code: Select all
// contents of $matches
// combine [1][0] with [2][0], [1][1] with [2][1], etc
Array
(
[0] => Array
(
[0] => OCT 28 29 NOV 03 04 05 10 11 DAILY 0800-SS
[1] => NOV 15 18 23 DAILY SR-SS
[2] => NOV 24 26 0700-1500
)
[1] => Array
(
[0] => OCT 28 29 NOV 03 04 05 10 11
[1] => NOV 15 18 23
[2] => NOV 24 26
)
[2] => Array
(
[0] => 0800-SS
[1] => SR-SS
[2] => 0700-1500
)
)