用PHP写一个备忘录的脚本
时间: 2023-09-20 08:03:00 浏览: 52
好的,以下是一个简单的备忘录脚本,使用PHP语言编写:
```php
<?php
// 设置文件路径
$file = "notes.txt";
// 获取表单数据
$note = $_POST["note"];
// 如果提交了表单
if(isset($_POST["submit"])) {
// 打开文件
$fp = fopen($file, "a");
// 写入备忘录
fwrite($fp, $note . "\n");
// 关闭文件
fclose($fp);
}
// 读取备忘录文件
$notes = file($file);
// 输出备忘录列表
foreach($notes as $note) {
echo $note . "<br>";
}
?>
<!-- 在HTML中添加表单 -->
<form method="post">
<textarea name="note"></textarea><br>
<input type="submit" name="submit" value="保存">
</form>
```
这个脚本会将用户输入的备忘录保存到名为 "notes.txt" 的文件中,并输出所有备忘录的列表。用户可以使用表单输入新的备忘录,然后点击 "保存" 按钮即可。
相关问题
请用c语言写一个备忘录
### 回答1:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_SIZE 100
int main() {
char memo[MAX_SIZE];
printf("请输入备忘录内容:\n");
fgets(memo, MAX_SIZE, stdin);
printf("您输入的备忘录内容是:%s", memo);
return ;
}
### 回答2:
备忘录是一种用来记录用户要做事项的工具。用户可以在备忘录中添加、查看和删除事项,以帮助他们管理日常任务。
以下是一个用C语言编写的备忘录的简单示例代码:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_NOTES 100
struct Note {
char content[100];
int id;
};
struct Note notes[MAX_NOTES];
int noteCount = 0;
void addNote() {
char content[100];
printf("请输入备忘录内容:");
scanf("%s", content);
struct Note newNote;
strcpy(newNote.content, content);
newNote.id = noteCount + 1;
notes[noteCount] = newNote;
noteCount++;
printf("已成功添加备忘录!\n");
}
void viewNotes() {
if (noteCount == 0) {
printf("备忘录为空。\n");
return;
}
printf("所有备忘录:\n");
for (int i = 0; i < noteCount; i++) {
printf("%d. %s\n", notes[i].id, notes[i].content);
}
}
void deleteNote() {
int noteId;
printf("请输入要删除的备忘录id:");
scanf("%d", ¬eId);
for (int i = 0; i < noteCount; i++) {
if (notes[i].id == noteId) {
for (int j = i; j < noteCount - 1; j++) {
notes[j] = notes[j + 1];
}
noteCount--;
printf("已成功删除备忘录!\n");
return;
}
}
printf("未找到该备忘录id。\n");
}
int main() {
int choice;
while (1) {
printf("\n备忘录菜单:\n");
printf("1. 添加备忘录\n");
printf("2. 查看所有备忘录\n");
printf("3. 删除备忘录\n");
printf("4. 退出\n");
printf("请输入你的选择:");
scanf("%d", &choice);
switch (choice) {
case 1:
addNote();
break;
case 2:
viewNotes();
break;
case 3:
deleteNote();
break;
case 4:
exit(0);
default:
printf("无效的选择。\n");
}
}
return 0;
}
```
这个备忘录程序使用了结构体数组来存储备忘录事项,并提供了添加、查看和删除事项的功能。用户可以通过输入菜单选项,进行相应的操作。在程序中,使用`noteCount`来跟踪备忘录事项的数量,以便轻松添加和删除事项。
### 回答3:
C语言是一种非常强大的编程语言,可以用来开发各种应用程序,包括备忘录。下面是一个简单的用C语言编写的备忘录示例:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_SIZE 100
typedef struct {
char title[50];
char content[200];
} Memo;
int main() {
Memo memos[MAX_SIZE];
int numMemos = 0;
while (1) {
int choice;
printf("备忘录操作:\n");
printf("1. 添加备忘录\n");
printf("2. 显示所有备忘录\n");
printf("3. 退出\n");
printf("请输入选项:");
scanf("%d", &choice);
switch (choice) {
case 1:
if (numMemos < MAX_SIZE) {
printf("请输入标题:");
scanf("%s", memos[numMemos].title);
printf("请输入内容:");
scanf("%s", memos[numMemos].content);
numMemos++;
printf("备忘录已添加!\n");
} else {
printf("备忘录已满,无法添加!\n");
}
break;
case 2:
if (numMemos > 0) {
printf("所有备忘录:\n");
for (int i = 0; i < numMemos; i++) {
printf("标题:%s\n", memos[i].title);
printf("内容:%s\n", memos[i].content);
printf("---------------\n");
}
} else {
printf("没有备忘录可显示!\n");
}
break;
case 3:
printf("退出备忘录程序!\n");
exit(0);
default:
printf("请输入有效选项!\n");
}
}
return 0;
}
```
这个简单的备忘录程序可以执行以下操作:
1. 添加备忘录:用户可以输入备忘录的标题和内容,最多可以添加100个备忘录。
2. 显示所有备忘录:程序会按照添加的顺序显示所有备忘录的标题和内容。
3. 退出:用户可以选择退出程序。
该备忘录程序使用了一个结构体来存储备忘录的标题和内容,并使用一个数组来保存所有的备忘录。在主循环中,根据用户的选择执行相应的操作,并根据需要输出相应的信息。
用 go 写一个备忘录
好的,我会尽力回答您的问题。下面是使用Go语言编写备忘录的示例代码:
```go
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
// 打开文件
file, err := os.OpenFile("notes.txt", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
fmt.Println(err)
return
}
defer file.Close()
// 获取用户输入的备忘信息
fmt.Print("请输入您要添加的备忘信息:")
reader := bufio.NewReader(os.Stdin)
note, _ := reader.ReadString('\n')
// 将备忘信息写入文件
_, err = file.WriteString(note)
if err != nil {
fmt.Println(err)
} else {
fmt.Println("备忘信息已经成功添加到文件中!")
}
}
```
这个程序将用户输入的备忘信息追加到一个名为 notes.txt 的文件中。如果该文件不存在,程序将创建它。
以上是示例代码,您可以根据自己的需求进行修改和优化。希望这能回答您的问题。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)