就像PHP的echo一样,PHP的print是一种语言构造,所以你不需要在参数列表中使用括号。print语句可以带有括号或不带括号:print和print()。与echo不同的是,它总是返回1。
PHP print的语法如下所示:
int print(string $arg)
PHP的print语句可以用于打印字符串、多行字符串、转义字符、变量、数组等。关于echo语句,你必须知道的一些重要事项有:
文件:print1.php
<?php
print "Hello by PHP print ";
print ("Hello by PHP print()");
?>
输出:
Hello by PHP print Hello by PHP print()
文件:print2.php
<?php
print "Hello by PHP print
this is multi line
text printed by
PHP print statement
";
?>
输出:
Hello by PHP print this is multi line text printed by PHP print statement
文件:print3.php
<?php
print "Hello escape \"sequence\" characters by PHP print";
?>
输出:
Hello escape "sequence" characters by PHP print
文件:print4.php
<?php
msg="Hello print() in PHP";
print "Message is:msg";
?>
输出:
Message is: Hello print() in PHP
本文链接:http://so.lmcjl.com/news/17844/