PHP echo() 函数
PHP 教程
· 2019-01-29 12:43:03
实例
输出一些文本:
<?php
echo "Hello world!";
?>
echo "Hello world!";
?>
定义和用法
echo() 函数输出一个或多个字符串。
注释:echo() 函数实际不是一个函数,所以您不必对它使用括号。然而,如果您想要传多于一个参数给 echo(),使用括号将会生成解析错误。
提示:echo() 函数比 print() 速度稍快。
提示:echo() 函数也有简化语法。在 PHP 5.4.0 版本之前,该语法只适用于 short_open_tag 配置设置启用的情况。
语法
echo(strings)
| 参数 | 描述 |
|---|---|
| strings | 必需。一个或多个要发送到输出的字符串。 |
技术细节
| 返回值: | 没有返回值。 |
|---|---|
| PHP 版本: | 4+ |
更多实例
实例 1
输出字符串变量($str)的值:
<?php
$str = "Hello world!";
echo $str;
?>
$str = "Hello world!";
echo $str;
?>
实例 2
输出字符串变量($str)的值,包含 HTML 标签:
<?php
$str = "Hello world!";
echo $str;
echo "<br>What a nice day!";
?>
$str = "Hello world!";
echo $str;
echo "<br>What a nice day!";
?>
实例 3
连接两个字符串变量:
<?php
$str1="Hello world!";
$str2="What a nice day!";
echo $str1 . " " . $str2;
?>
$str1="Hello world!";
$str2="What a nice day!";
echo $str1 . " " . $str2;
?>
实例 4
输出数组的值:
<?php
$age=array("Peter"=>"35");
echo "Peter is " . $age['Peter'] . " years old.";
?>
$age=array("Peter"=>"35");
echo "Peter is " . $age['Peter'] . " years old.";
?>
实例 5
输出一些文本:
<?php
echo "This text
spans multiple
lines.";
?>
echo "This text
spans multiple
lines.";
?>
实例 6
如何使用多个参数:
<?php
echo 'This ','string ','was ','made ','with multiple parameters.';
?>
echo 'This ','string ','was ','made ','with multiple parameters.';
?>
实例 7
单引号和双引号的区别。单引号将输出变量名称,而不是值:
<?php
$color = "red";
echo "Roses are $color";
echo "<br>";
echo 'Roses are $color';
?>
$color = "red";
echo "Roses are $color";
echo "<br>";
echo 'Roses are $color';
?>
实例 8
简化语法(只适用于 short_open_tag 配置设置启用的情况):
<?php
$color = "red";
?>
<p>Roses are <?=$color?></p>
$color = "red";
?>
<p>Roses are <?=$color?></p>
点击查看所有 PHP 教程 文章: https://codercto.com/courses/l/5.html
Design systems
Not all design systems are equally effective. Some can generate coherent user experiences, others produce confusing patchwork designs. Some inspire teams to contribute to them, others are neglected. S......一起来看看 《Design systems》 这本书的介绍吧!