当前位置: 首页> 函数类别大全> 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

    翻译字符或替换子字符串-转换指定字符
  • 反引用一个使用 addcslashes() 转义的字符串 stripcslashes

    stripcslashes

    反引用一个使用addcslashes()
  • 将二进制数据转换为十六进制表示 bin2hex

    bin2hex

    将二进制数据转换为十六进制表示
  • 返回有关字符串中使用的字符的信息-统计 string 中每个字节值(0..255)出现的次数 count_chars

    count_chars

    返回有关字符串中使用的字符的信息-统计s
  • 输出格式化的字符串 printf

    printf

    输出格式化的字符串
  • 将带引号的可打印字符串转换为8位字符串 quoted_printable_decode

    quoted_printable_decode

    将带引号的可打印字符串转换为8位字符串
  • 返回格式化的字符串 vsprintf

    vsprintf

    返回格式化的字符串
  • 输出一个字符串 print

    print

    输出一个字符串
热门文章