I have a POST form, than when submitted uses both key and value to replace lines in a set of .ini files.
$reading = fopen('Original/file.ini', 'r');
$writing = fopen('file.ini', 'w');
while (!feof($reading)) {
$line = fgets($reading);
foreach ( $_POST as $key => $value )
{
if (stristr($line, $key.)) {
$line = " ".$key." = ".$value.";
";
}
}
fputs($writing, $line);
}
fclose($reading); fclose($writing);
Now this is working fine. However, now I need to edit several files, of which many contains the same key. Of course, the file name and path the said files are not the same, so I was wondering if there's any way to group the text inputs, so I can keep using my PHP solution?
As an example, say I have both "product1.ini" and "product2.ini", but both have a "productPrice =" line. Any suggestions?
I would suggest changing the way you post the variables, so that the settings for each ini file are posted in an array named for that ini file.
So you'll be wanting to get a post array like this:
array(
'product1' => array(
'key1'=>'value1',
'key2'=>'value2'
),
'product2' => array(
'key1'=>'value1',
'key2'=>'value2'
),
)
This will give the ability to post settings for as many ini files as you like.
In case you haven't posted nested arrays before, this is easy to achieve. The HTML input field names just need to be formatted with the array keys in square brackets:
<input name='product1[key1]'>
Hope that helps.
I'm not sure if i understood you right, but in your html file you can create multiple text-boxes using same names by adding "[]" character to the end of name attribute
<input type="text" name="edit[]" />
<input type="text" name="edit[]" />
then in your php code you can get it as an array
var_dump($_POST['edit']);
//result: array(...)