PHP echo () function
Definition and Usage
echo () function outputs one or more strings.
NOTE: echo () function is not actually a function, so you do not have to use it in parentheses.However, if you want to pass more than one parameter to echo (), using parentheses will generate a parse error.
Tip: echo () function than the print () is slightly faster.
Tip: echo () function also has simplified syntax.Prior to PHP 5.4.0 version, this syntax applies only to short_open_tag configuration settings enabled.
grammar
参数 | 描述 |
---|---|
strings | 必需。一个或多个要发送到输出的字符串。 |
technical details
return value: | No return value. |
---|---|
PHP version: | 4+ |
More examples
Example 1
Output string variable ($ str) values:
$str = "Hello world!";
echo $str;
?>
Running instance »
Example 2
Output string variable ($ str) the value that contains HTML tags:
$str = "Hello world!";
echo $str;
echo "<br>What a nice day!";
?>
Running instance »
Example 3
Connecting two string variables:
$str1="Hello world!";
$str2="What a nice day!";
echo $str1 . " " . $str2;
?>
Running instance »
Example 4
Output array of values:
$age=array("Peter"=>"35");
echo "Peter is " . $age['Peter'] . " years old.";
?>
Running instance »
Example 6
How to use multiple parameters:
echo 'This ','string ','was ','made ','with multiple parameters.';
?>
Running instance »
Example 7
The difference between the single and double quotes. The output variable name in single quotes instead of value:
$color = "red";
echo "Roses are $color";
echo "<br>";
echo 'Roses are $color';
?>
Running instance »
Example 8
Simplified syntax (applies only to short_open_tag configuration settings enabled):
$color = "red";
?>
<p>Roses are <?=$color?></p>
Running instance »
PHP String Reference