PHP print() 函數(shù)
PHP String 參考手冊
實例
輸出一些文本:
<?php
print "Hello world!";
?>
運行實例 ?
定義和用法
print() 函數(shù)輸出一個或多個字符串。
注釋:print() 函數(shù)實際不是一個函數(shù),所以您不必對它使用括號。
提示:print() 函數(shù)比 echo() 速度稍慢。
語法
參數(shù) | 描述 |
strings | 必需。發(fā)送到輸出的一個或多個字符串。 |
技術(shù)細節(jié)
更多實例
實例 1
輸出字符串變量($str)的值:
<?php
$str = "Hello world!";
print $str;
?>
運行實例 ? 實例 2
輸出字符串變量($str)的值,包含 HTML 標(biāo)簽:
<?php
$str = "Hello world!";
print $str;
print "<br>What a nice day!";
?>
運行實例 ? 實例 3
連接兩個字符串變量:
<?php
$str1="Hello world!";
$str2="What a nice day!";
print $str1 . " " . $str2;
?>
運行實例 ? 實例 4
輸出數(shù)組的值:
<?php
$age=array("Peter"=>"35");
print "Peter is " . $age['Peter'] . " years old.";
?>
運行實例 ? 實例 5
輸出一些文本:
<?php
print "This text
spans multiple
lines.";
?>
運行實例 ? 實例 6
單引號和雙引號的區(qū)別。單引號將輸出變量名稱,而不是值::
<?php
$color = "red";
print "Roses are $color";
print "<br>";
print 'Roses are $color';
?>
運行實例 ?
PHP String 參考手冊