PHP print() 函數
語法
print(strings)
參數 | 描述 |
---|---|
strings | 必需。發送到輸出的一個或多個字符串。 |
技術細節
返回值: | 始終返回 1。 |
PHP 版本: | 4+ |
更多實例
例子 1
輸出字符串變量($str)的值:
<?php $str = "I love Shanghai!"; print $str; ?>
例子 2
輸出字符串變量($str)的值,包含 HTML 標簽:
<?php $str = "I love Shanghai!"; print $str; print "<br>What a nice day!"; ?>
例子 3
連接兩個字符串變量:
<?php $str1 = "I love Shanghai!"; $str2="What a nice day!"; print $str1 . " " . $str2; ?>
例子 4
輸出數組的值:
<?php $age=array("Bill"=>"60"); print "Bill Gates is " . $age['Bill'] . " years old."; ?>
例子 5
輸出文本:
<?php print "This text spans multiple lines."; ?>
例子 6
單引號和雙引號的區別。單引號將輸出變量名稱,而不是值:
<?php $color = "red"; print "Roses are $color"; print "<br>"; print 'Roses are $color'; ?>