我正在尝试创建一个可以编辑我网站上其他php文件的php文件。我能够做到这一点,除了我想编辑的php文件中有html。由于我使用textarea来显示/编辑php文件内容,因此当我想编辑的php文件中有textarea标记时,我所构建的内容不起作用。我到目前为止的内容如下。解决方案不需要像这样。
<?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>";
?>
答案 0 :(得分:0)
<?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>
答案 1 :(得分:-1)
<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>