[code]<html>

<head>
<title>Lineaire vergelijkingen</title>
</head>

<body>
<?php

error_reporting(E_ALL);

$valueof1 = '';
$valueof2 = '';
$valueof3 = '';
$valueof4 = '';

if(isset($_POST['1'],$_POST['2'],$_POST['3'],$_POST['4'])) {

	$_POST['1'] = preg_replace('/^([a-zA-Z]+?)$/','x', $_POST['1']);
	$_POST['2'] = preg_replace('/^([a-zA-Z]+?)$/','x', $_POST['2']);
	$_POST['3'] = preg_replace('/^([a-zA-Z]+?)$/','x', $_POST['3']);
	$_POST['4'] = preg_replace('/^([a-zA-Z]+?)$/','x', $_POST['4']);
	
	$valueof1 = ($_POST['1'] != 'x') ? htmlspecialchars($_POST['1']) : '1x';
	$valueof2 = ($_POST['2'] != 'x') ? htmlspecialchars($_POST['2']) : '1x';
	$valueof3 = ($_POST['3'] != 'x') ? htmlspecialchars($_POST['3']) : '1x';
	$valueof4 = ($_POST['4'] != 'x') ? htmlspecialchars($_POST['4']) : '1x';

	$points = 0;
	$numbers = array();
	$other = array();

	if(is_numeric($valueof1)) {
		$points += 1;
		$numbers[] = $valueof1;
	} else {
		$points -= 1;
		$other[] = ($valueof1 * -1).'x';
	}
	if(is_numeric($valueof2)) {
		$points += 1;
		$numbers[] = $valueof2;
	} else {
		$points -= 1;
		$other[] = ($valueof2 * -1).'x';
	}
	if(is_numeric($valueof3)) {
		$points += 1;
		$numbers[] = $valueof3 * -1;
	} else {
		$points -= 1;
		$other[] = $valueof3;
	}
	if(is_numeric($valueof4)) {
		$points += 1;
		$numbers[] = $valueof4 * -1;
	} else {
		$points -= 1;
		$other[] = $valueof4;
	}
	
	if($points == 0) {

		$num1 = $numbers[0];
		$num2 = $numbers[1];
		$num3 = $other[0];
		$num4 = $other[1];
		
		$result1 = preg_replace('/\+\+/', '+', $num1+$num2);
		$result2 = preg_replace('/\+\+/', '+', $num3+$num4);
		$result = $result1/$result2;

		$plus1 = (substr($num2, 0, 1) == '-') ? '' : '+';
		$plus2 = (substr($num4, 0, 1) == '-') ? '' : '+';
		echo "<b>Invoer:</b> ".$valueof1.$valueof2." = ".$valueof3.$valueof4."<br>\n";
		echo "<b>Stap 1:</b> ".$num1.$plus1.$num2." = ".$num3.$plus2.$num4."<br>\n";
		echo "<b>Stap 2:</b> ".preg_replace('/\+\+/', '+', $num1+$num2)." = ".preg_replace('/\+\+/', '+', $num3+$num4)."x<br>\n";
		echo "<b>Stap 3:</b> ".preg_replace('/\+\+/', '+', $num1+$num2)." / ".preg_replace('/\+\+/', '+', $num3+$num4)."x = ".$result."<br><br>\n";
	
		echo "Het resultaat van <b>".$valueof1." ".$valueof2." = ".$valueof3." ".$valueof4."</b> is dus <b>".$result."</b>.<br><br>\n";

	} else
		echo "<font color=\"red\">* Vul een juiste vergelijking in.</font><br><br>\n";

}

echo "Voorbeeld invoer: 5x +3 = 2x +9.<br>\n";
echo "Voor een juist antwoord zijn + en - tekens nodig, vul deze in in het tweede tekst vakje(voor en na de '=')!<br>\n";
echo "<form method=\"post\">\n";
echo "<input type=\"text\" name=\"1\" value=\"".$valueof1."\"> <input type=\"text\" name=\"2\" value=\"".$valueof2."\"> = <input type=\"text\" name=\"3\" value=\"".$valueof3."\"> <input type=\"text\" name=\"4\" value=\"".$valueof4."\"><br>\n";
echo "<input type=\"submit\" value=\"Bereken!\">\n";
echo "</form>\n";

?>
</body>

</html>[/code]