尝试通过表单的输入将大型html文档拼凑起来

时间:2019-02-01 05:03:08

标签: php html fopen fwrite

我正在尝试根据各个部分来构建文档。目标文档没有任何内容。

您能告诉我我在做什么错吗?

我有一个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"]));
?>

0 个答案:

没有答案