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

php心愿墙代码(用PHP写许愿墙)

作者:爱我者我必爱*   发布日期:2025-04-28   浏览:536

以下是一个简单的PHP许愿墙代码示例:

index.php:

<!DOCTYPE html>
<html>
<head>
    <title>许愿墙</title>
    <style>
        .wish {
            margin-bottom: 10px;
        }
    </style>
</head>
<body>
    <h1>许愿墙</h1>

    <form action="submit.php" method="POST">
        <textarea name="wish" placeholder="许下你的心愿"></textarea>
        <br>
        <input type="submit" value="许愿">
    </form>

    <h2>所有心愿</h2>
    <?php
    // 从文本文件中读取心愿列表
    $wishes = file("wishes.txt");

    // 遍历心愿列表并显示
    foreach ($wishes as $wish) {
        echo "<div class='wish'>" . htmlspecialchars($wish) . "</div>";
    }
    ?>
</body>
</html>

submit.php:

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // 获取提交的心愿内容
    $wish = $_POST["wish"];

    // 将心愿写入文本文件
    $file = fopen("wishes.txt", "a");
    fwrite($file, $wish . "\n");
    fclose($file);

    // 重定向回许愿墙页面
    header("Location: index.php");
    exit();
}
?>

上述代码中,index.php页面包含一个表单,用户可以在文本框中输入心愿并提交。表单的提交动作由submit.php处理。submit.php将接收到的心愿写入一个文本文件中,并通过重定向将用户返回到index.php页面。index.php页面会读取文本文件中的心愿列表,并将其显示在页面上。

上一篇:php超链接传递多个值(php超链接传递参数)

下一篇:php断点续传阿里云?(php 断点续传)

大家都在看

php session用法

phpisset函数

php后端

php爬虫框架

php读取csv文件

php 三元表达式

php文件加密

php 拆分字符串

php pcntl

php ||

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

Laravel 中文站