Add exams from exam58 to exam98

This commit is contained in:
2024-05-08 13:49:37 +02:00
parent 1bfdab1994
commit 4fd956ddac
39 changed files with 481 additions and 0 deletions

45
exam77/file.php Executable file
View File

@@ -0,0 +1,45 @@
<?php
//Writing to a file
// $handle = fopen('names.txt', 'w');
// fwrite($handle,'Alex' . "\n");
// fwrite($handle, 'Nikola');
// fclose($handle);
//Appending a file
if(isset($_POST['name'])){
$name = $_POST['name'];
if(!empty($name)){
$handle = fopen('names.txt', 'a');
fwrite($handle, $name ."\n");
fclose($handle);
echo 'Current names in file: ';
$count = 1;
$readin = file('names.txt');
$readin_count = count($readin);
foreach($readin as $fname){
echo trim($fname);
if($count < $readin_count){
echo ', ';
}
$count++;
}
} else {
echo 'Write some name!';
}
}
?>
<form action="file.php" method="POST">
Name:<br>
<input type="text" name="name"><br><br>
<input type="submit" value="Submit">
</form>

17
exam77/file2.php Normal file
View File

@@ -0,0 +1,17 @@
<?php
$filename = 'names.txt';
$handle = fopen($filename, 'r');
$datain = fread($handle, filesize($filename));
$names_array = explode(",", $datain);
foreach($names_array as $name){
echo $name . '<br>';
}
$string = implode(":", $names_array);
?>

12
exam77/names.txt Normal file
View File

@@ -0,0 +1,12 @@
Nicke,
Branko,
Steven,
Alex,
Sandra,
Sandra,
Dane,
Marko,
Krle,
Petar,
Aleksa,
Brana,