0

所以我不是很擅长 php,我有一个基本的评论系统,我正在尝试实现该系统的调用和写入 comments.php 文件。

一切都很好,直到我尝试对 $outputstring 进行一些样式设置。

这是我的代码

$outputstring = "<br><p><span class="label">Name:</span> " .$name. "</p><br> <p><span class="label">Comment:</span>" .$message. "</p><br>";

我知道是什么原因造成的

<span class="label"></span>

但谁能告诉我为什么?

在我尝试网站建设时,我得到的脚本只是 youtube 上的一个。

完整的脚本是这样的。

<?php
$act = $_POST['act'];
if($act == "post") {
$name = $_POST['name'];
$message  = $_POST ['message'];
@$fp = fopen("comments.php", 'a');
if (!$fp) {
    //The file could not be opened
    echo "There was an error! Please try again later!";
    exit;
} else {
    //The file was successfully opened, lets write the comment to it.
    $outputstring = "<br><p><span class="label">Name:</span> " .$name. "</p><br> <p><span class="label">Comment:</span>" .$message. "</p><br>";

    //Write to the file
    fwrite($fp, $outputstring, strlen($outputstring));

    //We are finished writing, close the file for security / memory management purposes
    fclose($fp);

    //Post the success message
    echo "Your post was successfully entered. Click <a href='index.php'>here</a> to continue.";
}
} else {
//We are not trying to post a comment, show the form.
?>
<h3>comments:</h3>
<hr/>
<?php include("comments.php"); ?>
<br><br>
<h3>Post a comment:</h3>
<form action="index.php" method="post">
<label>Name:<label>
<input type="text" name="name" value=""></input>
<br/>
<label>Comment:</label>
<textarea name="messages"></textarea>
<input type="hidden" name="act" value="post"></input>
<br/>
<input type="submit" name="submit" value="Submit"></input>
</form>
<?php
}
?>

如果有人能告诉我我需要做什么才能添加一个会膨胀的类的跨度。

谢谢。

4

3 回答 3

0

您不能在双引号内使用双引号,直到用反斜杠转义它们,在这种情况下,请使用单引号,而不是像这样

$outputstring = "<br><p><span class='label'>Name:</span> " .$name. "</p><br> <p><span class='label'>Comment:</span>" .$message. "</p><br>";
于 2013-05-16T10:00:42.890 回答
0
$outputstring = "<br><p><span class="label">Name:</span> " .$name. "</p><br> <p><span class="label">Comment:</span>" .$message. "</p><br>";

此行是错误的,因为您打破了行分隔符。对类属性使用单引号而不是双引号:

$outputstring = "<br><p><span class='label'>Name:</span> " .$name. "</p><br> <p><span class='label'>Comment:</span>" .$message. "</p><br>";

或者,如 chandresh_cool 所述,转义双引号。

于 2013-05-16T10:01:37.050 回答
0

$outputstring = '<br><p><span class="label">Name:</span> ' .$name. '</p><br> <p><span class="label">Comment:</span>' .$message. '</p><br>';当您没有动态值时,这应该可以解决您的问题。

于 2013-05-16T10:04:43.160 回答