目录

PHP print() 函数

❮ PHP 字符串参考

示例

将一些文本写入输出:

<?php
print "Hello world!";
?>
亲自试一试 »

定义和用法

print() 函数输出一个或多个字符串。

笔记:print() 函数实际上不是一个函数,因此您不需要在其中使用括号。

提示:print() 函数比回声()


语法

print( strings)

参数值

Parameter Description
strings Required. One or more strings to be sent to the output


技术细节

返回值: 总是返回 1
PHP 版本: 4+

更多示例

示例

将字符串变量 ($str) 的值写入输出:

<?php
$str = "Hello world!";
print $str;
?>
亲自试一试 »

示例

将字符串变量 ($str) 的值写入输出,包括 HTML 标签:

<?php
$str = "Hello world!";
print $str;
print "<br>What a nice day!";
?>
亲自试一试 »

示例

将两个字符串变量连接在一起:

<?php
$str1="Hello world!";
$str2="What a nice day!";
print $str1 . " " . $str2;
?> 
亲自试一试 »

示例

将数组的值写入输出:

<?php
$age=array("Peter"=>"35");
print "Peter is " . $age['Peter'] . " years old.";
?>
亲自试一试 »

示例

将一些文本写入输出:

<?php
print "This text
spans multiple
lines.";
?> 
亲自试一试 »

示例

单引号和双引号的区别。单引号将打印变量名称,而不是值:

<?php
$color = "red";
print "Roses are $color";
print "<br>";
print 'Roses are $color';
?>
亲自试一试 »

❮ PHP 字符串参考