从Text PHP继续格式化

时间:2014-09-25 12:42:39

标签: php text

我无法使用此代码保留我在文本区域中输入的格式:

<div class="col-md-12">
        <h1>
            <span class="glyphicon glyphicon-pencil"></span> Make a new Paste
        </h1>
        <form method="post" action="pastenew.php">
            <div class="panel panel-success">
                <div class="panel-heading">
                    <input type="text" name="title" placeholder="Paste Name" class="form-control input-title" value required>
                </div>
                <div class="panel-body">
                    <textarea rows="10" name="paste" placeholder="Insert your paste here" class="form-control input-paste" style="margin-top: 0; margin-bottom: 10px; height: 214px;" value required></textarea>
                    <div class="pull-left">
                        <button class="btn btn-success" type="submit">Submit Paste</button>
                        <button class="btn btn-danger" type="reset">Reset</button>
                    </div>
                </div>
            </div>
            <div class="alert alert-danger" style="font-size: 18px; text-align: center;">Still in development, come back later!</div>
        </form>
    </div>

当我按下提交时,它会打开一个新页面以及我所拥有的所有内容以测试它是否有效:

<!DOCTYPE HTML>
<html>
<body>
<?php echo $_POST["title"];?><br>
<?php echo $_POST["paste"];?>
</body>
</html>

但是不是将文本格式化,而是将其全部放在一行中。有办法解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

尝试使用 nl2br()

<?php echo nl2br($_POST["title"]); ?>
<?php echo nl2br($_POST["paste"];) ?>