Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在不使用html标记的情况下使用换行符?_Php - Fatal编程技术网

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

Php 如何在不使用html标记的情况下使用换行符?,php,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']); $querycommen

这是我的代码:

$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>
然后在注释列表中出现以下内容:

This is my world

为什么换行符不起作用?

因为换行符保存为
\n

您可以在回显字符串之前使用PHP函数

<?php
    $string = "This\nis\nmy\nworld";
    echo nl2br($string);
?>

因为换行符保存为
\n

您可以在回显字符串之前使用PHP函数

<?php
    $string = "This\nis\nmy\nworld";
    echo nl2br($string);
?>

类似于“如何在没有HTML的情况下使用HTML”问题您可以将输出包装在标记中类似于“如何在没有HTML的情况下使用HTML”问题您可以将输出包装在标记中