當前位置: 首頁> 函數類別大全> 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必需。發送到輸出的一個或多個字符串。
同類函數
  • 在字符串中查找一組字符的任何一個字符-返回一個以找到的字符開始的子字符串 strpbrk

    strpbrk

    在字符串中查找一組字符的任何一個字符-返
  • 從字符串的開頭刪除空格(或其他字符) ltrim

    ltrim

    從字符串的開頭刪除空格(或其他字符)
  • 輸出一個或多個字符串 echo

    echo

    輸出一個或多個字符串
  • 查找字符串的首次出現 strstr

    strstr

    查找字符串的首次出現
  • 使用一個字符串分割另一個字符串為數組 explode

    explode

    使用一個字符串分割另一個字符串為數組
  • 計算指定字符串在目標字符串中最後一次出現的位置(不區分大小寫) strripos

    strripos

    計算指定字符串在目標字符串中最後一次出現
  • 刪除字符串末端的空白字符(或者其他字符) rtrim

    rtrim

    刪除字符串末端的空白字符(或者其他字符)
  • 從字符串中刪除HTML和PHP標記 strip_tags

    strip_tags

    從字符串中刪除HTML和PHP標記
熱門文章