您的位置:首页 > 编程语言 > PHP开发

php打印函数

2015-11-05 11:16 483 查看

php打印函数总结 #

php的打印函数包括echo();print();die();printf();sprintf();print_r();var_dump()七种方式。

echo,echo(),ECHO

说明

echo
— 输出一个或多个字符串

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


输出所有参数。

echo 不是一个函数(它是一个语言结构), 因此你不一定要使用小括号来指明参数,单引号,双引号都可以。

echo (不像其他语言构造)不表现得像一个函数, 所以不能总是使用一个函数的上下文。 另外,如果你想给echo传递多个参数, 那么就不能使用小括号。

示例

echo "Hello World";
// You can use variables inside of an echo statement
$foo = "foobar";
echo "foo is $foo"; // foo is foobar
// You can also use arrays
$baz = array("value" => "foo");
echo "this is {$baz['value']} !"; // this is foo !
// Some people prefer passing multiple parameters to echo over concatenation.
echo 'This ', 'string ', 'was ', 'made ', 'with multiple parameters.', chr(10);
// 带标识符的字符串
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';
echo $some_var ? 'true': 'false'; // changing the statement around


注意:

1. echo并不能打印数组(数组的单个元素是可以的);

2. ECHO跟echo是等价的;

3. echo 也有一个快捷用法,你可以在打开标记前直接用一个等号。在 PHP 5.4.0 之前,必须在php.ini 里面启用 short_open_tag 才有效。
I have <?=$foo?> foo.


print,print(),PRINT()

说明

int print ( string $arg )

输出 arg。

print 实际上不是一个函数(它是一个语言结构),因此你可以不必使用圆括号来括起它的参数列表。

返回值 print(‘whatever’)总是返回 1。

示例

跟echo用法一致,故参见echo;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: