I have a group of 8 check boxes. Their values are integers, 1 - 8.
If a user selects any of the check boxes, I'm trying to change their values and then sum them up to create a single integer, which is then written to a file.
Now, for some reason, some of these work and some don't. For instance, selecting mode6 (value=6) writes as correctly 32, and mode7 writes correctly as 64 and if mode6 & 7 are selected, it writes correctly as 96. However, when mode3 is selected, it writes as 128. If mode1, 2 & 3 are selected, it writes as 131. Mode4 and 5 both write as 132. Mode1 and 2 work as intended, like 6 & 7.
Why are some working correctly, and others not? How can I get this working correctly all the way around😕
if(isset($_POST['mode'])) {
$anymode = ($_POST['mode']);
$patterns = array();
$patterns[0] = '/1/';
$patterns[1] = '/2/';
$patterns[2] = '/3/';
$patterns[3] = '/4/';
$patterns[4] = '/5/';
$patterns[5] = '/6/';
$patterns[6] = '/7/';
$patterns[7] = '/8/';
$replacements = array();
$replacements[0] = '1';
$replacements[1] = '2';
$replacements[2] = '4';
$replacements[3] = '8';
$replacements[4] = '16';
$replacements[5] = '32';
$replacements[6] = '64';
$replacements[7] = '128';
$oplmodes = preg_replace($patterns, $replacements, $anymode);
$oplmode = (array_sum($oplmodes));
}
if(isset($_POST['gamecode'])) {
$anycode = ($_POST['gamecode']);
$re1='((?:[a-z][a-z]+))';
$re2='.*?';
$re3='((?:[a-z][a-z]+))';
$re4='.*?';
$re5='(\\d+)';
$re6='.*?';
$re7='(\\d+)';
$re8='.*?';
$re9='(\\d+)';
$re10='.*?';
$re11='(\\d+)';
$re12='.*?';
$re13='(\\d+)';
if ($c=preg_match_all ("/".$re1.$re2.$re3.$re4.$re5.$re6.$re7.$re8.$re9.$re10.$re11.$re12.$re13."/is", $anycode, $matches))
{
$word1=strtoupper($matches[1][0]);
$word2=strtoupper($matches[2][0] . "_");
$int1=$matches[3][0];
$int2=$matches[4][0];
$int3=$matches[5][0];
$int4=$matches[6][0];
$int5=$matches[7][0];
$dirtygc = "$word1$word2$int1$int2$int3.$int4$int5";
}
}
$gamecf = $dirtygc . ".cfg";
$fh = fopen($gamecf, 'w') or die("can't open file");
$stringData = "\$Compatibility=$oplmode";
fwrite($fh, $stringData);
fclose($fh);
and here are my check boxes.
<td bgcolor="#003a39">
1<input type="checkbox" name="mode[]" id="mode1" value="1" />
2<input type="checkbox" name="mode[]" id="mode2" value="2" />
3<input type="checkbox" name="mode[]" id="mode3" value="3" />
4<input type="checkbox" name="mode[]" id="mode4" value="4" />
5<input type="checkbox" name="mode[]" id="mode5" value="5" />
6<input type="checkbox" name="mode[]" id="mode6" value="6" />
7<input type="checkbox" name="mode[]" id="mode7" value="7" />
8<input type="checkbox" name="mode[]" id="mode8" value="8" /></td>
Any help appreciated, thank you.