輸出一個字符串
print()
函數輸出一個或多個字符串。
註釋: print()
函數實際不是一個函數,所以您不必對它使用括號。
提示: print()
函數比echo()
稍慢。
向輸出寫入文本:
<?php print "I love Shanghai!" ; ?>
親自試一試
輸出字符串變量($str)的值:
<?php $str = "I love Shanghai!" ; print $str ; ?>
親自試一試
輸出字符串變量($str)的值,包含HTML 標籤:
<?php $str = "I love Shanghai!" ; print $str ; print "<br>What a nice day!" ; ?>
親自試一試
連接兩個字符串變量:
<?php $str1 = "I love Shanghai!" ; $str2 = "What a nice day!" ; print $str1 . " " . $str2 ; ?>
親自試一試
輸出數組的值:
<?php $age = array ( "Bill" => "60" ) ; print "Bill Gates is " . $age [ 'Bill' ] . " years old." ; ?>
親自試一試
輸出文本:
<?php print "This text spans multiple lines." ; ?>
親自試一試
單引號和雙引號的區別。單引號將輸出變量名稱,而不是值:
<?php $color = "red" ; print "Roses are $color " ; print "<br>" ; print 'Roses are $color' ; ?>
親自試一試
print ( strings )
參數 | 描述 |
---|---|
strings | 必需。發送到輸出的一個或多個字符串。 |