PHP的MySQL存储换行符在数据库中的文本区域 [英] php mysql storing line breaks in text area in database

查看:437
本文介绍了PHP的MySQL存储换行符在数据库中的文本区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个输入文本区域,我想将用户在数据库的文本区域中创建的换行符存储在其中,以便它以与输入文本相同的方式回显输出文本

I have an input textarea and I would like to store the line breaks that a user makes in the text area in the database, so that it echoes the output text the same way as in the input text

例如:

Some text some text some text some text


new line some text some text new line 

new line some text new line some text

这是我当前的上传脚本:

this is my current upload script:

$sql = "insert into people (price, contact, category, username, fname, lname, expire, filename) values (:price, :contact, :category, :user_id, :fname, :lname, now() + INTERVAL 1 MONTH, :imagename)";
$q = $conn->prepare($sql) or die("failed!");
$q->bindParam(':price', $price, PDO::PARAM_STR);
$q->bindParam(':contact', $contact, PDO::PARAM_STR);
$q->bindParam(':category', $category, PDO::PARAM_STR);
$q->bindParam(':user_id', $user_id, PDO::PARAM_STR);
$q->bindParam(':fname', $fname, PDO::PARAM_STR);
$q->bindParam(':lname', $lname, PDO::PARAM_STR);
$q->bindParam(':imagename', $imagename, PDO::PARAM_STR);
$q->execute();

推荐答案

文本区域中的换行符是换行符,例如\n.这些不是以HTML呈现的,因此,如果您仅回显输出,它们将不会显示.您可以在<textarea><pre>标记内回显,也可以使用 nl2br() <br>标签替换新行,以便可以将其显示为HTML.

The line breaks in the text area are linebreak characters such as \n. These are not rendered in HTML and thus they won't show up if you simply echo the output. You can echo inside of a <textarea> or a <pre> tag or you can use the nl2br() to replace new lines with <br> tags so that it can be displayed as HTML.

这篇关于PHP的MySQL存储换行符在数据库中的文本区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆