類似于PHP echo
語句,PHP print
是一個(gè)語言結(jié)構(gòu)(因?yàn)橛蟹祷刂担梢哉J(rèn)為它是函數(shù)),所以也不需要使用括號(hào)和參數(shù)列表。 與echo
不同,它總是返回1
。
PHP print
的語法如下:
int print(string $arg)
PHP print語句可以用來打印字符串,多行字符串,轉(zhuǎn)義字符,變量,數(shù)組等。
File: print1.php
<?php
print "Hello by PHP print ";
print ("Hello by PHP print()");
?>
執(zhí)行上面代碼得到以下結(jié)果 -
Hello by PHP print Hello by PHP print()
File: print2.php
<?php
print "Hello by PHP print
this is multi line
text printed by
PHP print statement
";
?>
執(zhí)行上面代碼得到以下結(jié)果 -
Hello by PHP print this is multi line text printed by PHP print statement
File: print3.php
<?php
print "Hello escape \"sequence\" characters by PHP print";
?>
執(zhí)行上面代碼得到以下結(jié)果 -
Hello escape "sequence" characters by PHP print
File: print4.php
<?php
$msg="Hello print() in PHP";
print "Message is: $msg";
?>
執(zhí)行上面代碼得到以下結(jié)果 -
Message is: Hello print() in PHP