PHP print() 函数
PHP 教程
· 2019-01-29 19:14:22
实例
输出一些文本:
<?php
print "Hello world!";
?>
print "Hello world!";
?>
定义和用法
print() 函数输出一个或多个字符串。
注释:print() 函数实际不是一个函数,所以您不必对它使用括号。
提示:print() 函数比 echo() 速度稍慢。
语法
print(strings)
| 参数 | 描述 |
|---|---|
| strings | 必需。发送到输出的一个或多个字符串。 |
技术细节
| 返回值: | 总是返回 1。 |
|---|---|
| PHP 版本: | 4+ |
更多实例
实例 1
输出字符串变量($str)的值:
<?php
$str = "Hello world!";
print $str;
?>
$str = "Hello world!";
print $str;
?>
实例 2
输出字符串变量($str)的值,包含 HTML 标签:
<?php
$str = "Hello world!";
print $str;
print "<br>What a nice day!";
?>
$str = "Hello world!";
print $str;
print "<br>What a nice day!";
?>
实例 3
连接两个字符串变量:
<?php
$str1="Hello world!";
$str2="What a nice day!";
print $str1 . " " . $str2;
?>
$str1="Hello world!";
$str2="What a nice day!";
print $str1 . " " . $str2;
?>
实例 4
输出数组的值:
<?php
$age=array("Peter"=>"35");
print "Peter is " . $age['Peter'] . " years old.";
?>
$age=array("Peter"=>"35");
print "Peter is " . $age['Peter'] . " years old.";
?>
实例 5
输出一些文本:
<?php
print "This text
spans multiple
lines.";
?>
print "This text
spans multiple
lines.";
?>
实例 6
单引号和双引号的区别。单引号将输出变量名称,而不是值::
<?php
$color = "red";
print "Roses are $color";
print "<br>";
print 'Roses are $color';
?>
$color = "red";
print "Roses are $color";
print "<br>";
print 'Roses are $color';
?>
点击查看所有 PHP 教程 文章: https://www.codercto.com/courses/l/5.html
The Master Switch
Tim Wu / Knopf / 2010-11-2 / USD 27.95
In this age of an open Internet, it is easy to forget that every American information industry, beginning with the telephone, has eventually been taken captive by some ruthless monopoly or cartel. Wit......一起来看看 《The Master Switch》 这本书的介绍吧!