echo
(PHP 3, PHP 4, PHP 5 )
echo -- 1つ以上の文字列を出力する
説明
echo ( string arg1 [, string argn...])
この関数は、すべてのパラメータを出力します。
echo() は実際には関数ではありません。
(言語構造です。)このため、使用する際に括弧は必要ありません。実際、
複数のパラメータを指定して echo をコールしたい場合、括弧の中にパ
ラメータを記述するべきではありません。
例 1. echo() の例
<?php echo "Hello World";
echo "This spans multiple lines. The newlines will be output as well"; echo "This spans\nmultiple lines. The newlines will be\noutput as well.";
echo "escaping characters is done \"Like this\"."
// echo 命令の中で変数を使用することが可能です $foo = "foobar"; $bar = "barbaz";
echo "foo is $foo"; // foo は foobar です。
// 値ではなく変数名を出力するシングルクオートを使用する。 echo 'foo is $foo'; //
// 他の文字を全く使用しない場合、echo 変数を使用可能です。 echo $foo; // foobar echo $foo,$bar; // foobarbarbaz
echo <<<END This uses the "here document" syntax to output multiple lines with $variable interpolation. Note that the here document terminator must appear on a line with just a semicolon no extra whitespace! END;
// echo は関数ではないので以下のコードは正しくありません ($some_var) ? echo('true'): echo('false');
// しかし、次の例は動作します。 ($some_var) ? print('true'): print('false'); // print は関数 echo $some_var ? 'true': 'false'; // 命令を変更 ?>
|
|
echo() には、次のように開始タグのすぐ後に等号
を付ける省略形があります。
print(),
printf(),
flush() も参照下さい。