如何在不使用html标签的情况下使用换行符?

xRo*_*bot 0 php

这是我的代码:

$blogid = mysql_real_escape_string($_GET['id']); 

if((isset($_POST['comment']))&&(!(trim($_POST['comment'])==FALSE))&&(isset($_SESSION['userid']))){

   $comment = mysql_real_escape_string($_POST['comment']); 
   $querycomment = "INSERT INTO `comment` (`userid`, `blogid`, `body`) VALUES ( '".$_SESSION['userid']."', '".$blogid."', '".$comment."');";
   $rowchat = mysql_query($querymess,$db_con) or die("Failed: " . mysql_error() );

}

<form method="post" action="blog.php?id=<?php echo $blogid; ?>" >
<textarea name="comment" ></textarea>
<input type="submit" value="send" name="submit" />
</form>
Run Code Online (Sandbox Code Playgroud)

当用户对此发表评论时:

This
is
my
world
Run Code Online (Sandbox Code Playgroud)

然后在评论列表中显示:

This is my world
Run Code Online (Sandbox Code Playgroud)

为什么断线不起作用?

h2o*_*ooo 5

因为换行符保存为\n.

您可以nl2br($string)在回显字符串之前使用PHP函数.

<?php
    $string = "This\nis\nmy\nworld";
    echo nl2br($string);
?>
Run Code Online (Sandbox Code Playgroud)