Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

php图标变成记事本(php记事本源码)

作者:淡情   发布日期:2025-04-27   浏览:666

以下是一个简单的PHP记事本的源代码示例:

index.php:

<!DOCTYPE html>
<html>
<head>
    <title>PHP记事本</title>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
    <div class="container">
        <h1>PHP记事本</h1>
        <form action="save_note.php" method="POST">
            <textarea name="note" placeholder="在这里输入你的笔记"></textarea>
            <button type="submit">保存</button>
        </form>
        <h2>已保存的笔记:</h2>
        <div class="notes">
            <?php
            // 读取保存的笔记
            $notes = file_get_contents('notes.txt');
            if (!empty($notes)) {
                $notes = explode("\n", $notes);
                foreach ($notes as $note) {
                    echo "<div class='note'>" . $note . "</div>";
                }
            }
            ?>
        </div>
    </div>
</body>
</html>

save_note.php:

<?php
// 获取提交的笔记内容
$note = $_POST['note'];

// 保存笔记到文件
$file = fopen('notes.txt', 'a');
fwrite($file, $note . "\n");
fclose($file);

// 重定向回主页
header('Location: index.php');
?>

style.css:

.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 20px;
}

h1 {
    text-align: center;
}

form textarea {
    width: 100%;
    height: 100px;
    margin-bottom: 10px;
}

form button {
    display: block;
    margin: 0 auto;
}

h2 {
    margin-top: 20px;
}

.notes {
    border: 1px solid #ccc;
    padding: 10px;
}

.note {
    margin-bottom: 10px;
}

这个记事本应用使用一个文本文件来保存笔记。用户可以在文本框中输入笔记,然后点击保存按钮将笔记保存到文件中。已保存的笔记将在页面上显示出来。

上一篇:PHP降序用什么函数实现?(php快速排序代码)

下一篇:php 调用接口登陆(php调用api)

大家都在看

php session用法

phpisset函数

php后端

php爬虫框架

php读取csv文件

php 三元表达式

php文件加密

php 拆分字符串

php pcntl

php ||

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站