0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

PHPで\nを改行させる方法

Last updated at Posted at 2021-10-07

PHPだと文字列に\nが入っていても改行されない。

ただの空白として出力される。

解決方法

$summary = "abc\ndef\nghi";

//改行されない通常のコード
echo($summary);

//改行されるコード
echo(nl2br($summary));

nl2br関数を使うと、stringに含まれるすべての改行文字(\r\n,\n\r,\n,\r) の前に<br />あるいは<br>を挿入して返してくれる。

参考

PHPのお役立ち情報

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?