0
1

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 改行コードはPHP_EOLを使おう

Posted at

概要

  • PHPでの改行はPHP_EOLを使ったほうが良いらしいので簡単にまとめてみる。

PHPの改行

  • 「独習PHP(第3版)」を読むと改行の説明に\nを使っている。
  • ただし、これはLinuxやMacOSの場合のみでWindowsの場合は\r\nを使う様にも記載されている。
  • 環境に依存したコードはなるべく書きたく無いものである。

PHP_EOL

  • PHP_EOLはPHPで最初から定義されている定数のことで、「行末文字」を示している。

  • 環境に依存せず、改行を表すことができる。

  • 下記の2行はLinuxやMacOSの環境なら同じ出力がなされる。

    <?php
    
    echo "朝ごはんを" . "\n" . "食べました。" . "\n";
    echo "朝ごはんを" . PHP_EOL . "食べました。" . PHP_EOL;
    
0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?