我在一个 html 列表元素中有这个 php 脚本,如果变量 ?pw =“密码”,它允许用户直接从网页编辑 html 元素。我希望用户也能够添加列表项供他们编辑,有没有办法使用 php 在 html 中附加另一个列表项?我知道你可以在 javascript 中使用 .append() ......这是我正在谈论的 php 脚本:
<li>
<?php
if ($_POST['pw']!="") {
$pw=($_POST['pw']);
} else {
$pw=($_GET['pw']);
}
$newcontent2=($_POST['newcontent2']);
$filelocation2 = "content/event2-1.txt";
if (!file_exists($filelocation2)) {
echo "Couldn't find datafile, please contact the administrator. huberwb@g.cofc.edu";
} else {
$newfile2 = fopen($filelocation2,"r");
$content2 = fread($newfile2, filesize($filelocation2));
fclose($newfile2);
}
$content2 = stripslashes($content2);
$content = htmlentities($content2,ENT_HTML5);
/*set password */
$pass = "password";
if (!$pw || $pw != $pass){
$content2 = nl2br($content2);
echo $content2;
} else {
if($newcontent2){
$newcontent2 = stripslashes($newcontent2);
$newfile2 = fopen($filelocation2,"w");
fwrite($newfile2, $newcontent2);
fclose($newfile2);
echo "Text has been edited.";
echo "<form><input type= 'submit' value='see changes' class='button'/></form>";
} else {
echo "<form method='post'> <textarea name ='newcontent2' style= 'width:100px; height:20px; border: 3px solid # ccc; font-family: sans-serif; font-size:small;' cols ='auto' rows='auto' wrap='virtual'>";
echo $content2;
echo "</textarea>
<input type='hidden' name='pw' value= '".$pass."' />
<br /><input type='submit' value='edit' class='button' />
</form>";
}
}
?>
</li>