I want to write a script that will read in a css file, allow the user to alter the settings via a form and then save the file. The problem I'm having is in figuring out the best way to cross-reference the array I read in and the fields read from the form. This is the code I wrote to read in the css file. It creates a multi-array with each class from the css file in its only array.
Code:
function GetClasses($cssFile)
{
$classesArray = array();
if (($fp = @file($cssFile)))
{
$i = 0;
$start = false;
foreach ($fp as $line)
{
if ($line[0] == '#')
{
$classesArray[$i][] = $line;
$start = true;
}
else if ($start)
{
$classesArray[$i][] = $line;
if ($line[0] == '}')
{
$i++;
$start = false;
}
}
}
}
return $classesArray;
}
Let's say the above creates this array
Code:
Array
(
[0] => Array
(
[0] => #nav, #nav ul {
[1] => float: left;
[2] => width: 58em;
)
[1] => Array
(
[0] => #nav a {
[1] => font-family: Tahoma, Verdana, sans-serif;
[2] => font-size: .8em;
[5] => width: 7em;
)
}
and that the form is setup to hold those values
Code:
<input type="text" name="nav_float"
<input type="text" name="nav_width"
<input type="text" name="nav_a_font_family"
<input type="text" name="nav_a_width"
How do I read in the form elements and match them to the correct array element? The only way I can think of is to assign numbers to the form elements, like
Code:
<input type="text" name="0_0_nav_float"
<input type="text" name="0_1_nav_width"
<input type="text" name="1_0_nav_a_font_family"
<input type="text" name="1_1_nav_a_width"
Then I would explode each name and match it to the array element using those keys but that seems awfully convoluted. Is there some better way to do this?