-=ВДРЕБЕЗГИ=-, Я вот как раз недавно написал свой первый калькулятор
код (+/-)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="style.css?<?=rand(1,5000);?>" />
<title>Калькулятор</title>
</head>
<body>
<div class="top">
<form id="top" action="func.php" method="post">
<input type="text" name="mytext" size="10" />
<input type="text" name="msg" size="10" />
<input type="submit" name="1" value="+" />
<input type="submit" name="2" value="-" />
<input type="submit" name="3" value="*" />
<input type="submit" name="4" value="/" />
</form>
</div>
<?php
if ($_POST['1']=='+'){
function calc($one, $two){
$plus = $one + $two;
return $plus;
}
echo '<div class="top"><p>'. calc($_POST['mytext'], $_POST['msg']) .'</p></div><br /><br />';
echo '<div class="clear"></div>';
} elseif ($_POST['2']=='-'){
function calc($one, $two){
$minus = $one - $two;
return $minus;
}
echo '<div class="top"><p>'. calc($_POST['mytext'], $_POST['msg']) .'</p></div><br /><br />';
echo '<div class="clear"></div>';
} elseif ($_POST['3']=='*'){
function calc($one, $two){
$umn = $one * $two;
return $umn;
}
echo '<div class="top"><p>'. calc($_POST['mytext'], $_POST['msg']) .'</p></div><br /><br />';
echo '<div class="clear"></div>';
} elseif ($_POST['4']=='/' & $_POST['mytext'] !=='' & $_POST['msg'] !==''){
function calc($one, $two){
$razd = $one / $two;
return $razd;
}
echo '<div class="top"><p>'. calc($_POST['mytext'], $_POST['msg']) .'</p></div><br /><br />';
echo '<div class="clear"></div>';
} else {
echo '<div class="top"><p>0</p></div><br /><br />';
echo '<div class="clear"></div>';
}
?>
</body>
</html>