Skip to content

Commit 5665761

Browse files
committed
Debugging todo.php
1 parent d39a092 commit 5665761

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

codeup_todo_list/data/test.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
// }
2020
// fclose($handle);
2121

22-
$new_tasks = ['Wash the car', 'Play the drums', 'Write some blogs', 'Manage social media', 'Profit'];
22+
// $new_tasks = ['Wash the car', 'Play the drums', 'Write some blogs', 'Manage social media', 'Profit'];
2323

24-
$filename = "todo_list.txt";
25-
$handle = fopen($filename, 'a');
26-
foreach ($new_tasks as $task) {
27-
fwrite($handle, PHP_EOL . $task);
28-
}
29-
fclose($handle);
24+
// $filename = trim(fgets(STDIN));
25+
// $handle = fopen($filename, "w");
26+
// foreach ($new_tasks as $task) {
27+
// fwrite($handle, $task . PHP_EOL);
28+
// }
29+
// fclose($handle);
3030
?>

codeup_todo_list/todo.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ function read_file($fileRead, $itemlist) {
3838

3939
function save_file($arrayname){
4040
echo "Enter filename: ";
41+
4142
$filename = get_input();
4243
$handle = fopen($filename, "w");
4344
foreach ($arrayname as $task) {
44-
fwrite($handle, PHP_EOL . $task);
45+
fwrite($handle, $task . PHP_EOL);
4546
} fclose($handle);
4647
}
4748

@@ -102,12 +103,22 @@ function save_file($arrayname){
102103

103104
} elseif ($input == 'M') {
104105
echo "(O)pen or (S)ave file? ";
105-
$filename = get_input(TRUE);
106-
if($input == 'S'){
107-
save_file($items);
108-
echo "File saved. ";
106+
$input = get_input(TRUE);
107+
if($input == 'S'){
108+
echo "Doing this will overwrite your file. Is that okay? Y or N? ";
109+
$input = get_input(TRUE);
110+
if ($input == 'Y') {
111+
save_file($items);
112+
echo "File saved. " . PHP_EOL;
113+
} elseif ($input == 'N') {
114+
echo "Returning to menu." . PHP_EOL;
115+
continue;
116+
}
117+
109118
} elseif($input == 'O') {
110-
$items = read_file($filename, $items);
119+
echo "Enter filename: ";
120+
$filename = get_input();
121+
$items = read_file($filename, $items);
111122
}
112123
}
113124
// Exit when input is (Q)uit

0 commit comments

Comments
 (0)