如何在php中创建php文件编辑器


How do you create a php file editor in php

我正在尝试创建一个php文件,可以编辑我网站上的其他php文件。我能够做到这一点,除非php文件中有我想要编辑的html。由于我使用文本区域来显示/编辑php文件内容,因此当php文件中有我想要编辑的文本区域标记时,我所构建的内容将不起作用。到目前为止,我所掌握的内容如下。解决方案不需要类似于此。

<?php
if ($_POST['file_text']){
file_put_contents($_POST['filename'], $_POST['file_text']);
$filename = $_POST['filename'];
echo "<script>
window.location = '_editor.php?filenm=$filename'
</script>";
}
else {
$myfilename = $_GET['filenm'];
if(file_exists($myfilename)){
$file_text= file_get_contents($myfilename);
}
echo "
<h3>$myfilename</h3>
<form name='input' action='_editor.php?filenm=$myfilename' method='post'>
<textarea name='contrib_entrybox' id='contrib_entrybox' rows='50' cols='180'>
$file_text
</textarea>";
?>
<?php
    // configuration
    $url = 'http://domain.com/backend/editor.php';
    $yourfilePath = '/path/to/txt/file';
    // check if form has been submitted
    if (isset($_POST['text'])){
        // save the text contents
        file_put_contents($yourfilePath, $_POST['text']);
        // redirect to form again
        header(sprintf('Location: %s', $url));
        printf('<a href="%s">Moved</a>.', htmlspecialchars($url));
        exit();
    }
    // read the textfile
    $text = file_get_contents($yourfilePath);
?>
<!-- HTML form -->
<form action="" method="post">
    <textarea name="text"><?php echo htmlspecialchars($text) ?></textarea>
    <input type="submit" />
    <input type="reset" />
</form>

<div id="sample">
  <script type="text/javascript" src="http://js.nicedit.com/nicEdit-latest.js"></script> <script type="text/javascript">
        bkLib.onDomLoaded(function() { nicEditors.allTextAreas() });
 
  </script>
  <h4>
    Second Textarea
  </h4>
  <textarea name="area2" style="width: 100%;">
       Some Initial Content was in this textarea
</textarea><br />
            
</div>