-
-
Save nizom333/35d60c03491ccf3207287ea2e1ef5af1 to your computer and use it in GitHub Desktop.
PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
// Задача 1 | |
$bmw = array( | |
"model" => "x5", | |
"speed" => 120, | |
"doors" => 5, | |
"year" => "2006" | |
); | |
$toyota = array( | |
"model" => "Carina", | |
"speed" => 130, | |
"doors" => 4, | |
"year" => "2007" | |
); | |
$opel = array( | |
"model" => "Corsa", | |
"speed" => 140, | |
"doors" => 5, | |
"year" => "2007" | |
); | |
$arCars = array($bmw, $toyota, $opel); | |
foreach ($arCars as $key => $value){ | |
echo $value['model'] . ' - ' . $value['speed'] . ' - ' . $value['doors'] . ' - ' . $value['year'] .'<br><br>'; | |
} | |
// Задача 2 | |
$cols=10; | |
$rows=10; | |
echo "<table border='1'>"; | |
for( $i = 1; $i <= $rows; $i++ ){ | |
echo "<tr>"; | |
for( $td = 1; $td <= $cols; $td++ ){ | |
echo "<td>".$i*$td."</td>"; | |
} | |
echo "</tr>"; | |
} | |
echo "</table>"; | |
// Задача 3 | |
echo "<h1>Заполните форму!"; | |
?> | |
<form action="<?=$_SERVER['PHP_SELF']?>" method="post"> | |
Имя: <input type="text" name="fname" required><br> | |
Фамилия: <input type="text" name="lname" required><br><br> | |
<input type="submit" value="Отправить"> | |
</form> | |
<? | |
define('log', 'log'); | |
if(isset($_POST['fname']) && !empty($_POST['fname']) && isset($_POST['lname']) && !empty($_POST['lname'])){ | |
$html.= "Имя: ". $_POST['fname']."\n"; | |
$html.= "фамилия: ". $_POST['lname']."\n\n"; | |
$file = $_SERVER["DOCUMENT_ROOT"]."/nizom/".log.".txt"; | |
$data = file_get_contents($file); | |
file_put_contents($file, $html.$data); | |
}else{ | |
echo "Заполните все поля"; | |
} | |
if(file_exists($file)){ | |
$fp = fopen($file, 'r'); | |
if ($fp) | |
{ | |
while (!feof($fp)) | |
{ | |
$mytext = fgets($fp, 999); | |
echo $mytext."<br /><br />"; | |
} | |
echo 'Размер файла ' . log.".txt" . ': ' . filesize(log.".txt") . ' байтов'."<br /><br />"; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Задачи по php