开发者

save text as pre in mysql database

I have a textarea and users can type in it. I want to store what they type in a MySQL database but I want to output it with the right amount of spaces like HTML's <pre></pre>. How can I save their input in a database without ruining these spaces?

My code so far just looks like:

<form action='index.php' method='POST'>
<textarea id='area'></textarea>
<input type='submit' value='submit'>
<?php 

$input=$_POST['input'];
//mysql query goes开发者_如何学C here ()


It has been a while since I did this, but here's what I remember: the database doesn't remove the spaces. Two things control the spacing: the textarea's wrap command and the way you show the data later when you retrieve it from the database.

For my forms (that do this successfully) I use textarea wrap="soft"

Then when you take it out of the database you can use pre tags to show it or if you are using php you can use nl2br() on the text to change newlines to html break tags.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜