当前位置: 首页> 函数类别大全> 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 必需。发送到输出的一个或多个字符串。
同类函数
  • 从数字生成单字节字符串 chr

    chr

    从数字生成单字节字符串
  • 将字符串中每个单词的首字母转换为大写 ucwords

    ucwords

    将字符串中每个单词的首字母转换为大写
  • 打断字符串为指定数量的字串 wordwrap

    wordwrap

    打断字符串为指定数量的字串
  • 检查字符串是否以给定的子字符串开头 str_starts_with

    str_starts_with

    检查字符串是否以给定的子字符串开头
  • 将特殊字符转换为HTML实体 htmlspecialchars

    htmlspecialchars

    将特殊字符转换为HTML实体
  • rtrim的别名 chop

    chop

    rtrim的别名
  • 对字符串执行rot13转换 str_rot13

    str_rot13

    对字符串执行rot13转换
  • 标记分割字符串 strtok

    strtok

    标记分割字符串
热门文章