Add exams from exam58 to exam98
This commit is contained in:
45
exam77/file.php
Executable file
45
exam77/file.php
Executable 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
17
exam77/file2.php
Normal 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
12
exam77/names.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
Nicke,
|
||||
Branko,
|
||||
Steven,
|
||||
Alex,
|
||||
Sandra,
|
||||
Sandra,
|
||||
Dane,
|
||||
Marko,
|
||||
Krle,
|
||||
Petar,
|
||||
Aleksa,
|
||||
Brana,
|
||||
Reference in New Issue
Block a user