3
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 5 years have passed since last update.

【PHP】\nや\tはダブルクオーテーションで囲う

Last updated at Posted at 2019-01-03

タイトルそのままです。
シングルクオーテーションだと、ただの文字列として出力されてしまいます。

test.php
<?php
// \nで改行
echo 'test1'.'\n';
echo 'test2'."\n";

// \tでタブ表示
echo 'test3'.'\t'.'test3-2'."\n";
echo 'test4'."\t".'test4-2'."\n";

出力結果

test1\ntest2
test3\ttest3-2
test4	test4-2

html上で改行させたい場合に使う<br>タグは、シングルクオーテーションで問題ありません。

バックスラッシュを使用する場合は、挙動の違いに気をつけたいと思います。

php.net〜エスケープシーケンス

3
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
3
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?