In PHP, there are two basic output methods: Echo and Print.
PHP Echo and Print statements
The difference between Echo and print:
echo - 能够输出一个以上的字符串print - 只能输出一个字符串,并始终返回 1
Tip: Echo is slightly faster than print because it does not return any values.
PHP Echo Statement
Echo is a language structure that can be used with or without parentheses: Echo or Echo ().
Display string
The following example shows how to display different strings with the echo command (also note that the string can contain HTML tags):
echo"PHP is fun!
";echo"Hello world!
";echo"I'm about to learn PHP!
";echo"This", " string", " was", " made", " with multiple parameters.";?>
The following example shows how to use the echo command to display strings and variables:
$txt1="Learn PHP";$txt2="W3School.com.cn";$cars=array("Volvo","BMW","SAAB");echo$txt1;echo"
";echo"Study PHP at $txt2";// 单引号解析不了变量$echo"My car is a {$cars[0]}";?>
PHP Print Statement
Print is also a language structure and can be used with or without parentheses: print or print ().
Display string
The following example shows how to use the Print command to display different strings (also note that the string can contain HTML tags):
print"PHP is fun!
";print"Hello world!
";print"I'm about to learn PHP!";?>
Show variables
The following example shows how to use the Print command to display strings and variables:
$txt1="Learn PHP";$txt2="W3School.com.cn";$cars=array("Volvo","BMW","SAAB");print$txt1;print"
";print"Study PHP at $txt2";print"My car is a {$cars[0]}";?>
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The above describes the 8 PHP 5 echo and Print statements, including the aspects of the content, I hope to be interested in PHP tutorial friends helpful.