А сегодня закончил ещё один калькулятор, но уже по-серьёзнее
код (+/-)
<!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);?>" />
<script type="text/javascript">
function setFocus(){
document.getElementById("act").focus(); // Активируем поле "act"
input = document.getElementById("act");
input.selectionStart = input.value.length; // Ставим каретку в конец поля "act"
}
</script>
<title>Калькулятор</title>
</head>
<body onload="setFocus();">
<div class="">
<form id="top" action="fcalk.php" method="post">
<input id="act" type="text" name="msg" size="18" value="
<?php
///// ПРИБАВЛЕНИЕ /////
if (!empty($_POST['msg']) && $_POST['1']=='+'){
$file = fopen('z:\home\my.ru\www\index.txt','w'); // Открываем файл
$str = $_POST['msg'].'+'; // Данные для записи
if(!$file){
exit();
} else {
fputs($file, $str); // Записываем данные в файл
}
readfile('index.txt');
fclose($file); // Закрываем файл
}
if (!empty($_POST['msg']) && $_POST['5']=='='){
$file = fopen('z:\home\my.ru\www\index.txt','w'); // Открываем файл
$str = $_POST['msg']; // Данные для записи
if(!$file){
exit();
} else {
fputs($file, $str); // Записываем данные в файл
}
fclose ($file); // Закрываем файл
$st = 'z:\home\my.ru\www\index.txt'; // Получаем содержимое файла в строку
$file = fopen($st,'r'); // Открываем файл
$data = fread($file, filesize($st)); // Считываем и пишем данные в $data
$arr = explode('+', $data); // Разбиваем строку на элементы массива
$pos = strpos($data, '+'); // Ищем вхождение '+'
echo $result=($pos==true)?$arr[0]+$arr[1]:'';
fclose($file);
}
///// ВЫЧИТАНИЕ /////
if (!empty($_POST['msg']) && $_POST['2']=='-'){
$file = fopen('z:\home\my.ru\www\index.txt','w');
$str = $_POST['msg'].'-';
if(!$file){
exit();
} else {
fputs($file, $str);
}
readfile('index.txt');
fclose($file);
}
if (!empty($_POST['msg']) && $_POST['5']=='='){
$file = fopen('z:\home\my.ru\www\index.txt','w');
$str = $_POST['msg'];
if(!$file){
exit();
} else {
fputs($file, $str);
}
fclose ($file);
$st = 'z:\home\my.ru\www\index.txt';
$file = fopen($st,'r');
$data = fread($file, filesize($st));
$arr = explode('-', $data);
$pos = strpos($data, '-');
echo $result=($pos==true)?$arr[0]-$arr[1]:'';
fclose($file);
}
///// УМНОЖЕНИЕ /////
if (!empty($_POST['msg']) && $_POST['3']=='*'){
$file = fopen('z:\home\my.ru\www\index.txt','w');
$str = $_POST['msg'].'*';
if(!$file){
exit();
} else {
fputs($file, $str);
}
readfile('index.txt');
fclose($file);
}
if (!empty($_POST['msg']) && $_POST['5']=='='){
$file = fopen('z:\home\my.ru\www\index.txt','w');
$str = $_POST['msg'];
if(!$file){
exit();
} else {
fputs($file, $str);
}
fclose ($file);
$st = 'z:\home\my.ru\www\index.txt';
$file = fopen($st,'r');
$data = fread($file, filesize($st));
$arr = explode('*', $data);
$pos = strpos($data, '*');
echo $result=($pos==true)?$arr[0]*$arr[1]:'';
fclose($file);
}
///// ДЕЛЕНИЕ /////
if (!empty($_POST['msg']) && $_POST['4']=='/'){
$file = fopen('z:\home\my.ru\www\index.txt','w');
$str = $_POST['msg'].'/';
if(!$file){
exit();
} else {
fputs($file, $str);
}
readfile('index.txt');
fclose($file);
}
if (!empty($_POST['msg']) && $_POST['5']=='='){
$file = fopen('z:\home\my.ru\www\index.txt','w');
$str = $_POST['msg'];
if(!$file){
exit();
} else {
fputs($file, $str);
}
fclose ($file);
$st = 'z:\home\my.ru\www\index.txt';
$file = fopen($st,'r');
$data = fread($file, filesize($st));
$arr = explode('/', $data);
$pos = strpos($data, '/');
if($pos==true){
if($arr[0] !="" && $arr[1] !=0){
echo $result=$arr[0]/$arr[1];
}
}
fclose($file);
}
?>" /><br />
<input type="submit" name="5" value="=" />
<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>
</body>
</html>