导航首页 » 技术教程 » PHP字符串函数print()的用法
PHP字符串函数print()的用法 138 2023-12-12   

print

(PHP 4, PHP 5)

print — 输出字符串

说明

int print ( string $arg )

输出 arg

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

参数

arg

输入数据。

返回值

总是返回 1。

范例

Example #1 print 范例

<?php
print("Hello World");

print "print() also works without parentheses.";

print "This spans
multiple lines. The newlines will be
output as well";

print "This spansnmultiple lines. The newlines will benoutput as well.";

print "escaping characters is done "Like this".";

// 可以在打印语句中使用变量
$foo = "foobar";
$bar = "barbaz";

print "foo is $foo"; // foo is foobar

// 也可以使用数组
$bar = array("value" => "foo");

print "this is {$bar['value']} !"; // this is foo !

// 使用单引号将打印变量名,而不是变量的值
print 'foo is $foo'; // foo is $foo

// 如果没有使用任何其他字符,可以仅打印变量
print $foo;          // foobar

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

注释

Note: 因为是一个语言构造器而不是一个函数,不能被 可变函数 调用。

参见

echo - 输出一个或多个字符串 printf() - 输出格式化字符串 flush() - 刷新输出缓冲 Heredoc syntax


!!!站长长期在线接!!!

网站、小程序:定制开发/二次开发/仿制开发等

各种疑难杂症解决/定制接口/定制采集等

站长微信:lxwl520520

站长QQ:1737366103