echo

(PHP 4, PHP 5, PHP 7)

echo锟斤拷锟揭伙拷锟斤拷锟斤拷锟斤拷址锟斤拷锟�

说锟斤拷

echo ( string $arg1 [, string $... ] ) : void

锟斤拷锟斤拷锟斤拷胁锟斤拷锟斤拷锟斤拷锟斤拷峄伙拷小锟�

echo 锟斤拷锟斤拷一锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷一锟斤拷锟斤拷锟皆结构锟斤拷锟斤拷 锟斤拷锟斤拷悴灰伙拷锟揭癸拷锟叫★拷锟斤拷锟斤拷锟街革拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷牛锟剿拷锟斤拷哦锟斤拷锟斤拷浴锟� echo 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟皆癸拷锟届)锟斤拷锟斤拷锟街碉拷锟斤拷一锟斤拷锟斤拷锟斤拷锟斤拷 锟斤拷锟皆诧拷锟斤拷锟斤拷锟斤拷使锟斤拷一锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟侥★拷 锟斤拷锟解,锟斤拷锟斤拷锟斤拷锟斤拷echo 锟斤拷锟捷讹拷锟斤拷锟斤拷锟斤拷锟� 锟斤拷么锟酵诧拷锟斤拷使锟斤拷小锟斤拷锟脚★拷

echo 也锟斤拷一锟斤拷锟斤拷锟斤拷梅锟斤拷锟斤拷锟斤拷锟斤拷锟节打开憋拷锟角爸憋拷锟斤拷锟揭伙拷锟斤拷群拧锟斤拷锟� PHP 5.4.0 之前锟斤拷锟斤拷锟斤拷锟斤拷php.ini 锟斤拷锟斤拷锟斤拷锟斤拷 short_open_tag 锟斤拷锟斤拷效锟斤拷

I have <?=$foo?> foo.

锟斤拷 print 锟斤拷锟斤拷要锟侥诧拷同之锟斤拷锟角o拷 echo 锟斤拷锟杰诧拷锟斤拷锟叫憋拷锟斤拷锟斤拷没锟叫凤拷锟斤拷值锟斤拷

锟斤拷锟斤拷

arg1

要锟斤拷锟斤拷牟锟斤拷锟�

...

锟斤拷锟斤拷值

没锟叫凤拷锟斤拷值锟斤拷

锟斤拷锟斤拷

Example #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\".";

// You can use variables inside of an echo statement
$foo "foobar";
$bar "barbaz";

echo 
"foo is $foo"// foo is foobar

// You can also use arrays
$baz = array("value" => "foo");

echo 
"this is {$baz['value']} !"// this is foo !

// Using single quotes will print the variable name, not the value
echo 'foo is $foo'// foo is $foo

// If you are not using any other characters, you can just echo variables
echo $foo;          // foobar
echo $foo,$bar;     // foobarbarbaz

// Strings can either be passed individually as multiple arguments or
// concatenated together and passed as a single argument
echo 'This ''string ''was ''made ''with multiple parameters.'chr(10);
echo 
'This ' 'string ' 'was ' 'made ' 'with concatenation.' "\n";

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;

// Because echo does not behave like a function, the following code is invalid.
($some_var) ? echo 'true' : echo 'false';

// However, the following examples will work:
($some_var) ? print 'true' : print 'false'// print is also a construct, but
                                            // it behaves like a function, so
                                            // it may be used in this context.
echo $some_var 'true''false'// changing the statement around
?>

注锟斤拷

Note: 锟斤拷为锟斤拷一锟斤拷锟斤拷锟皆癸拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷一锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟杰憋拷 锟缴变函锟斤拷 锟斤拷锟矫★拷

Tip

锟斤拷锟� echo 锟斤拷拼锟斤拷锟街凤拷锟斤拷锟斤拷锟皆o拷锟斤拷锟捷讹拷锟斤拷锟斤拷锟斤拷冉虾茫锟斤拷锟斤拷堑锟斤拷锟� PHP 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟�"."锟斤拷锟斤拷锟斤拷锟饺硷拷锟斤拷 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷要圆锟斤拷锟脚憋拷证锟斤拷锟饺硷拷锟斤拷

<?php
echo "Sum: "2;
echo 
"Hello ", isset($name) ? $name "John Doe""!";

锟斤拷锟斤拷锟狡达拷拥模锟斤拷锟斤拷锟节加号猴拷锟斤拷目元锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷"."锟斤拷锟斤拷锟叫革拷锟斤拷锟斤拷锟饺硷拷锟斤拷为锟斤拷锟斤拷确锟皆o拷锟斤拷锟斤拷使锟斤拷圆锟斤拷锟脚o拷

<?php
echo 'Sum: ' . (2);
echo 
'Hello ' . (isset($name) ? $name 'John Doe') . '!';

锟轿硷拷

  • print - 锟斤拷锟斤拷址锟斤拷锟�
  • printf() - 锟斤拷锟斤拷锟绞斤拷锟斤拷址锟斤拷锟�
  • flush() - 刷锟斤拷锟斤拷锟斤拷锟斤拷锟�
  • Heredoc 锟斤法