php - 尝试将大型 html 文档与来自表单的输入拼凑在一起
问题描述
我正在尝试从其各个部分构建文档。目标文档未获取任何内容。
你能告诉我我在这里做错了什么吗?
我有一个begin.txt
内容HTML
和一个end.txt
我想继续将新代码(newarticle.txt)添加到开头的内容,以便每次添加新代码时它都会向前流动。然后我想把它全部放在一起articles.html
。
<?php
$v1 = $_POST["url"]; //You have to get the form data
$v2 = $_POST["description"];
$v3 = $_POST["date"];
$destination = fopen('articles.html', 'w+');
$begin = fopen('begin.txt','w+');
$end = fopen('end.txt','w+');
$currentend = file_get_contents('/end.txt');
$currentbegin = file_get_contents('/begin.txt');
$file = fopen('newarticle.txt', 'w+'); //Open your .txt file
ftruncate($file, 0); //Clear the file to 0bit
// $content = <li><a href=$v1. PHP_EOL .$v2. PHP_EOL .$v3;
$build1 = <<<EOF
<li><a href="$v1">$v2</li>
<li>$v3</li>
EOF;
fwrite($file , $build1); //Now lets write it in there
fclose($file ); //Finally close our .txt
$file = "newarticle.txt";
$currentfile = file_get_contents($file);
$build2 = <<<EOF
$build1
$currentend
EOF;
ftruncate($end, 0); //Clear the file to 0bit
fwrite ($end , $build2);
fclose ($end );
$updatedend = 'end.txt';
$updatedendcontent = file_get_contents($updatedend);
ftruncate($destination, 0);
$build3 = <<<EOF
$currentbegin
$updatedendcontent
EOF;
fwrite ($destination , $build3);
fclose ($destination );
die(header("Location: ".$_SERVER["HTTP_REFERER"]));
?>
修复它,这有效
<?php
$v1 = $_POST["url"]; //You have to get the form data
$v2 = $_POST["description"];
$v3 = $_POST["date"];
// $begin = fopen('begin.txt','w+');
$currentend = file_get_contents('end.txt');
$currentbegin = file_get_contents('begin.txt');
$file = fopen('newarticle.txt', 'w+'); //Open your .txt file
ftruncate($file, 0); //Clear the file to 0bit
// $content = <li><a href=$v1. PHP_EOL .$v2. PHP_EOL .$v3;
$build1 = <<<EOF
<li><a href="$v1">$v2</li>
<li>$v3 by Accounting Today</li>
EOF;
fwrite($file , $build1); //Now lets write it in there
fclose($file ); //Finally close our .txt
//$file = "newarticle.txt";
$currentfile = file_get_contents('newarticle.txt');
$build2 = <<<EOF
$build1
$currentend
EOF;
$end = fopen('end.txt','w+');
ftruncate($end, 0); //Clear the file to 0bit
fwrite ($end , $build2);
fclose ($end );
//$updatedend = 'end.txt';
$updatedendcontent = file_get_contents('end.txt');
$build3 = <<<EOF
$currentbegin
$updatedendcontent
EOF;
$destination = fopen('articles.html', 'w+');
ftruncate($destination, 0);
fwrite ($destination , $build3);
fclose ($destination );
die(header("Location: ".$_SERVER["HTTP_REFERER"]));
?>
解决方案
推荐阅读
- python - 如何找到python整数列表的对称部分并获得该对称部分的总和?
- javascript - 我想比较数组并将相同的值放在一起
- javascript - 如何使用 JSDOC 从对象的值创建联合
- python - Python中散点图的大小图例
- python - 为什么“列宽”设置为不同的值?
- python - 将数据框的每一行值与第一行进行比较,以查看从起点开始的变化
- swift - swiftUI,NavigationView既有.NavigationBarTitle和.NavigationBarItems.Console打印约束冲突
- sql - LIKE 子句中的正则表达式,仅接受字母数字和破折号
- php - Symfony 没有加载我定义为服务的自定义验证器
- javascript - SPA 如何处理未修改的 304 响应