I am needing a little help with splitting the contents of a file into a multidimensional array.
Sample of the file contents :
--[DEATH KNIGHT]--
--|Blood|--
--{Single}--
/* MACRO CODE FOR SINGLE TARGET */
--{MULTI}--
/* MACRO CODE FOR MULTIPLE TARGETS */
--|Frost|--
/* MACRO CODE FOR SINGLE TARGET */
--{MULTI}--
/* MACRO CODE FOR MULTIPLE TARGETS */
--{Single}--
--[DRUID]--
--|Guardian|--
--{Single}--
/* MACRO CODE FOR SINGLE TARGET */
--{Multi}--
/* MACRO CODE FOR MULTIPLE TARGETS */
I need to read this file and split it into an array with the following structure :
array(
'DEATHKNIGHT' => array(
'Blood' => array(
'Single' = 'Single Target Macro Code',
'Multi' = 'Multiple Target Macro Code'
),
'Frost' => array(
'Single' = 'Single Target Macro Code',
'Multi' = 'Multiple Target Macro Code'
)
),
'DRUID' => array(
'Guardian' => array(
'Single' = 'Single Target Macro Code',
'Multi' = 'Multiple Target Macro Code'
)
)
I am using file_get_contents() to read the contents of the file into a string. I I am using preg_match_all() to pull out my defined array keys. The following are the regex that I am using:
$class_regex = '/(?:-{2})(?:\[)(?:[A-Z][\w]+)(?:[\s][A-Z][\w]+)?(?:\])(?:-{2})/';
$spec_regex = '/(?:-{2})(?:\|)(?:[A-Z][\w]+)(?:[\s][A-Z][\w]+)?(?:\|)(?:-{2})/i';
$target_regex = '/(?:-{2})(?:\{)(?:[A-Z][\w]+)(?:[\s][\(][\d][\D][\)])?(?:\})(?:-{2})/i';
I can pull out the keys successfully, and I can seperate the file into specific elements, but I am struggling when trying to create my array. Any help would be greatly appreciated. Thank you in advance.
while ($line = fgets($file))instead of reading the whole thing withfile_get_contents().SingleandMultistatic(constant) within your file content?