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>
|
||||
Reference in New Issue
Block a user