<?php
$formNames = [
'Заявление и согласие на обработку персональных данных',
'Что-то ещё'
];
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
foreach ($_FILES['userFile']['name'] as $k => $name) {
$filename = $formNames[$k] . '.' . pathinfo($name, PATHINFO_EXTENSION);
$uploadFile = __DIR__ . DIRECTORY_SEPARATOR . $filename;
move_uploaded_file($_FILES['userFile']['tmp_name'][$k], $uploadFile);
}
}
?>
<form enctype="multipart/form-data" method="post">
<?php foreach ($formNames as $formName) { ?>
<p><?=$formName?><br><input type="file" name="userFile[]"></p>
<?php } ?>
<input type="submit" value="Отправить">
</form>
$export = 'export.txt';
$import = 'import.txt';
$exp = fopen($export, 'r');
$imp = fopen($import, 'a');
$switch = false;
while ($line = fgets($exp)) {
$line = trim($line);
$line != '@export_end@' ?: $switch = false;
! $switch ?: fputs($imp, $line . PHP_EOL);
$line != '@export_start@' ?: $switch = true;
}
fclose($exp);
fclose($imp);
<?php
$file = 'data.txt';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$a = $_POST['a'] ?? null;
$b = $_POST['b'] ?? null;
if (isset($a, $b)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($file).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . mb_strlen("$a\n$b"));
exit("$a\n$b");
} else {
exit('Оба поля обязательны для заполнения!');
}
}
?>
<form method="post">
<p>Значение 1 <input type="text" name="a" placeholder="12345"></p>
<p>Значение 2 <input type="text" name="b" placeholder="54321"></p>
<p><input type="submit"></p>
</form>
не думал что скобки помогают
~<span>(?:Game|Игра)</span>~m
//$str = 'Иванов Иван Иванович 01.01.1970 353';
$str = 'Иванов Иван 01.01.1970 353';
extract( splitLineBySpace($str) );
var_dump($lastname, $firstname, $secondname, $birthdate, $number);
function splitLineBySpace(string $str): array
{
$lastname = $firstname = $secondname = $birthdate = $number = '';
$patt = '~(\S+)\h(\S+)(?:\h(\S+))?\h((?:\d\d\.){2}\d{4})\h(\d+)~';
if (preg_match($patt, $str, $arr)) {
if (count($arr) == 6) {
[, $lastname, $firstname, $secondname, $birthdate, $number] = $arr;
} else {
[, $lastname, $firstname, $birthdate, $number] = $arr;
}
}
return compact('lastname', 'firstname', 'secondname', 'birthdate', 'number');
}
$str = 'post/123';
if (preg_match("#^post/(?P<name>\d+)$#", $str, $arr)) {
var_dump($arr);
}
В результате будет массив: