程序代码 程序代码

<?php
echo “Hello World”;           //最简单的用法,同ASP中的response.write “Hello World”;

echo “This spans
multiple lines. The newlines will be
output 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

//最有用的echo用法,使用<<<加上标识符来开始一段输出,引号不用转义表示,可直接输出.记得结尾要用同样的标识符结束

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