<?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
// Some people prefer passing multiple parameters to echo over concatenation.
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
?>
====================
PHP die() 函数
PHP 杂项函数
定义和用法
die() 函数输出一条消息,并退出当前脚本。
该函数是 exit() 函数的别名。
语法
die(status)参数 描述
status 必需。规定在退出脚本之前写入的消息或状态号。状态号不会被写入输出。
说明
如果 status 是字符串,则该函数会在退出前输出字符串。
如果 status 是整数,这个值会被用作退出状态。退出状态的值在 0 至 254 之间。退出状态 255 由 PHP 保留,不会被使用。状态 0 用于成功地终止程序。
提示和注释
注释:如果 PHP 的版本号大于等于 4.2.0,那么在 status 是整数的情况下,不会输出该参数。
例子
<?php
$site = "http://www.w3school.com.cn/";
fopen($site,"r")
or die("Unable to connect to $site"
|