如何设置“if”;在php中设置变量文本的条件


How to set "if" conditions the variable text in php?

我想创建一个PHP主页,可以写在评论保存到一个空白的HTML页面。我想让网站管理员写在地方的'名称'代码漆红色的消息和显示的名称称为一个主人。我尝试了附加的代码,但它不适合我,它在"名称"的地方写了代码,并写了"经理"和默认颜色的消息。这可能是因为我不知道PHP中变量的良好条件(这是我第一次使用这种语言…)有人能修复我的代码吗?tnx !

这里是我的代码:

<?php
if ($_POST){
$name = $_POST['name'];
$content = $_POST['commentContent'];
$handle = fopen("comments.html","a");
if ($_POST['name']=="d1234"){
$_POST['name']="maneger";
fwrite ($handle,"<hr><b>" . "<h2 style=" . "color:red;" . ">" . $name . "                       </h2></b></br>" . "color:red;" . $content . "</br><hr>");
fclose ($handle);
}
else{
fwrite ($handle,"<hr><b>" . "<h2 style=" . "color:blue;" . ">" . $name . "</h2></b></br>"  . $content . "</br><hr>"); 
fclose ($handle);
}
}
?>
<html>
<body>
<form action="" method="POST">
Comment: <textarea rows ="3" cols ="30" name="commentContent"></textarea>    </br>
 name:    <input type = "text" name = "name"></br>
<input type = "submit" value = "!פרסם"></br>
</form>
<?php include "comments.html"; ?>
</body>
</html>

答案在这里

if ($_POST){
$name = $_POST['name'];
$content = $_POST['commentContent'];
$handle = fopen("comments.html","a");
if ($_POST['name']=="d1234"){
$name = "Maneger";
fwrite ($handle, "<hr><b>" . "<h2 style=" . "color:red;" . ">" . $name . "     </h2></b></br>" .  $content . "</br><hr>");
fclose ($handle);
}
else{
fwrite ($handle,"<hr><b>" . "<h2 style=" . "color:blue;" . ">" . $name . "</h2></b></br>"  . $content . "</br><hr>"); 
fclose ($handle);
}
}