當前位置: 首頁> 函數類別大全> print

print

輸出一個字符串
名稱:print
分類:字符串
所屬語言:php
一句話介紹:輸出一個或多個字符串。

定義和用法

print()函數輸出一個或多個字符串。

註釋: print()函數實際不是一個函數,所以您不必對它使用括號。

提示: print()函數比echo()稍慢。

實例

例子1

向輸出寫入文本:

 <?php
print "I love Shanghai!" ;
?>

親自試一試

例子2

輸出字符串變量($str)的值:

 <?php
$str = "I love Shanghai!" ;
print $str ;
?>

親自試一試

例子3

輸出字符串變量($str)的值,包含HTML 標籤:

 <?php
$str = "I love Shanghai!" ;
print $str ;
print "<br>What a nice day!" ;
?>

親自試一試

例子4

連接兩個字符串變量:

 <?php
$str1 = "I love Shanghai!" ;
$str2 = "What a nice day!" ;
print $str1 . " " . $str2 ;
?> 

親自試一試

例子5

輸出數組的值:

 <?php
$age = array ( "Bill" => "60" ) ;
print "Bill Gates is " . $age [ 'Bill' ] . " years old." ;
?>

親自試一試

例子6

輸出文本:

 <?php
print "This text
spans multiple
lines." ;
?> 

親自試一試

例子7

單引號和雙引號的區別。單引號將輸出變量名稱,而不是值:

 <?php
$color = "red" ;
print "Roses are $color " ;
print "<br>" ;
print 'Roses are $color' ;
?>

親自試一試

文法

print ( strings )
參數 描述
strings 必需。發送到輸出的一個或多個字符串。
同類函數
  • 翻譯字符或替換子字符串-轉換指定字符 strtr

    strtr

    翻譯字符或替換子字符串-轉換指定字符
  • 使用“自然順序”算法進行字符串比較 strnatcmp

    strnatcmp

    使用“自然順序”算法進行字符串比較
  • 使用反斜線轉義字符串 addslashes

    addslashes

    使用反斜線轉義字符串
  • 返回有關字符串中使用的單詞的信息 str_word_count

    str_word_count

    返回有關字符串中使用的單詞的信息
  • 查詢語言和區域設置信息 nl_langinfo

    nl_langinfo

    查詢語言和區域設置信息
  • 返回字符串的一部分 substr

    substr

    返回字符串的一部分
  • 使用uuencode 編碼一個字符串 convert_uuencode

    convert_uuencode

    使用uuencode編碼一個字符串
  • 根據指定格式解析輸入的字符 sscanf

    sscanf

    根據指定格式解析輸入的字符
熱門文章