echo nl2br("これ\r\nは\r\nどう表示される");

<?php
$content = $_POST['content'];
if(!empty($content)){
echo nl2br($content);
} else {
}
?>
<form method="post" action="/">
<textarea name="content" rows="4" cols="40"></textarea>
<input type="submit" value="送信">
</form>
なるほどー

あれ、まてよ。pdoでmysqlに入れてみます。
$content = $_POST['content'];
if(!empty($content)){
$value = nl2br($content);
} else {
}
try {
$pdo = new PDO('mysql:host=localhost;dbname=test;charset=utf8','root','',
array(PDO::ATTR_EMULATE_PREPARES => false));
} catch (PDOException $e) {
exit('データベース接続失敗。'.$e->getMessage());
}
$stmt = $pdo -> prepare("INSERT INTO news (content) VALUES (:content)");
$stmt->bindParam(':content', $value, PDO::PARAM_STR);
$stmt->execute();
echo "成功";
?>
<form method="post" action="/">
<textarea name="content" rows="4" cols="40"></textarea>
<input type="submit" value="送信">
</form>
mysql> alter table news change content content varchar(100);
Query OK, 4 rows affected (0.24 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql> describe news;
+---------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| content | varchar(100) | YES | | NULL | |
+---------+--------------+------+-----+---------+----------------+
2 rows in set (0.03 sec)
mysql> select * from news;
+----+----------------------------------+
| id | content |
+----+----------------------------------+
| 1 | テスト |
| 2 | 10byte以上を入 |
|
|
| 5 | ほげほげ
ふぉおお |
+----+----------------------------------+
5 rows in set (0.00 sec)
なんだ、行けるじゃん。
textareaで改行した値をmysqlに格納することは可能。
