我使用以下脚本在我的服务器上编辑基于文本的文件(TXT、HTML、PHP等)
<?php
    $filename = "test.php";
    function make_content_file($filename,$content,$opentype="w")
    {
        $fp_file = fopen($filename, $opentype);
        fputs($fp_file, $content);
        fclose($fp_file);
    }
    if($_POST)
    {
         $newcontents=$_POST[newcontents];
         make_content_file($filename,$newcontents);
    }
    $filecontents = file_get_contents($filename);
?>
<?php
    if($_POST)
    {
        echo '<p><span style="font-weight: 700; background-color: #CCFFCC">You have successfully posted to your txt file!</span></p>
        <a href="".$filename."">Download</a>';
    }
?>
<form method="post">
    <textarea name="newcontents" cols="70" rows="25"><?=$filecontents?></textarea>
    <br>
    <input type="submit" value="Save">  
</form>该脚本可以很好地处理大多数PHP文件示例:

但是,如果一个文件包含一些带有文本区域的表单,那么代码就会变得一团糟。
示例:

另一个例子:http://i.imgur.com/P9O34Y8.png
想知道为什么会发生这种情况,以及如何解决,谢谢。
发布于 2020-05-12 00:20:42
第一个评论总结了这一切
有趣的事实:我自己也有一个类似的工具,可以从书签、清空文件功能和sha1 密码保护中编辑文件。
希望它真的有用
if (sha1($_POST['pass']) != $pass) {
    echo "<style>input{padding:0.1em; font-size:1.1em}body{background:$bg; color:$fg; font-family:corbel;font-size:1.4vw;padding:0.4em}a{color:$fg}</style><body><h2>$nick<mark>:)</mark></h2>";
    echo '
        <form action="writer.php" method="post">
        Code: <input type="password" name="pass" autofocus>
        <input type="hidden" name="f" value="'.$_GET['f'].'"><br><br>';
    if ($_POST['pass'] != ""){
        echo 'Incorrect code.';
    }
}若要清空文件,请键入“空”。若要在使用前设置密码,请遍历前5行代码,并修改$pass。确保密码是安全和唯一的(14+字符)
https://stackoverflow.com/questions/23804593
复制相似问题