-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
28 lines (24 loc) · 961 Bytes
/
functions.php
File metadata and controls
28 lines (24 loc) · 961 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php
function read($filename, $operation)
{
$data = [];
$files = fopen($filename, 'r');
if (!$files) return false;
while (!feof($files)) { // пока файл не закончиться, продолжаем цикл
$line = fgets($files, 9999); // читаем строки в файле ограничение 9999 строк
$data = explode(" ", $line);
$result = eval("return " . $data['0'] . $operation . $data['1'] . ";");
if ($result > 0)
writeAnswers("+", $result, $operation);
else
writeAnswers("-", $result, $operation);
}
fclose($files);
return "Результаты у вас в папке :) ";
}
function writeAnswers($filename, $txt, $operation)
{
$file = fopen($filename, "a") or die("Unable to open file!");
fwrite($file, $txt . "\n");
fclose($file);
}