PHP echo() 函数
PHP String 函数
定义和用法
echo() 函数输出一个或多个字符串。
语法
echo(strings)
参数
描述
strings
必需。一个或多个要发送到输出的字符串。
提示和注释
注释:echo() 实际上不是一个函数,因此您无需对其使用括号。不过,如果您希望向 echo() 传递一个或多个参数,那么使用括号会发生解析错误。
提示:echo() 函数比 print() 函数快一点点。
提示:echo() 函数可以使用简化语法。参见例子 5。
例子
例子 1
$str = "Who's John Adams?";
echo $str;
echo "
";
echo $str."
I don't know!";
?>
输出:
Who's John Adam?
Who's John Adam?
I don't know!
例子 2
echo "This text
spans multiple
lines.";
?>
输出:
This text spans multiple lines.
例子 3
echo 'This ','string ','was ','made ','with multiple parameters';
?>
输出:
This string was made with multiple parameters
例子 4
单引号和双引号的不同之处。单引号仅输出变量名,而不是值:
$color = "red";
echo "Roses are $color";
echo "
";
echo 'Roses are $color';
?>
输出:
Roses are red
Roses are $color
例子 5
简化语法:
$color = "red";
?>
Roses are =$color?>
PHP String 函数