您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
三六零分类信息网 > 阜阳分类信息网,免费分类信息发布

php print函数怎么用

2026/4/23 23:46:47发布8次查看
php print函数用于输出一个或多个字符串,其语法是print(strings),参数strings必需,指发送到输出的一个或多个字符串。print()函数实际不是一个函数,所以您不必对它使用括号。
php print函数怎么用?
定义和用法
print() 函数输出一个或多个字符串。
注释:print() 函数实际不是一个函数,所以您不必对它使用括号。
提示:print() 函数比 echo() 稍慢。
语法
print(strings)
参数
strings 必需。发送到输出的一个或多个字符串。
返回值: 始终返回 1。
php 版本: 4+
例子 1
输出字符串变量($str)的值:
<?php$str = "i love shanghai!";print $str;?>
输出:
i love shanghai!

例子 2
输出字符串变量($str)的值,包含 html 标签:
<?php$str = "i love shanghai!";print $str;print "<br>what a nice day!";?>
输出:
i love shanghai!what a nice day!
例子 3
连接两个字符串变量:
<?php$str1 = "i love shanghai!";$str2="what a nice day!";print $str1 . " " . $str2;?>
输出:
i love shanghai! what a nice day!
例子 4
输出数组的值:
<?php$age=array("bill"=>"60");print "bill gates is " . $age['bill'] . " years old.";?>
输出:
bill gates is 60 years old.
例子 5
输出文本:
<?phpprint "this textspans multiplelines.";?>
输出:
this text spans multiple lines.
例子 6
单引号和双引号的区别。单引号将输出变量名称,而不是值:
<?php$color = "red";print "roses are $color";print "<br>";print 'roses are $color';?>
输出:
roses are redroses are $color
例子 7
向输出写入文本:
<?phpprint "i love shanghai!";?>
输出:
i love shanghai!

以上就是php print函数怎么用的详细内容。
阜阳分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product