PHP

PHP Echo/Print

小7 · 12月7日 · 2020年

PHP echo 和 print 语句

echo – 能够输出一个以上的字符串

print – 只能输出一个字符串,并始终返回1


PHP echo 语句

echo 语言结构,有无括号都可以用:echoecho()

echo字符串中可以包含HTML标记

<?php
echo "<h2>PHP 很有趣</h2>";
echo "Hello world!<br>";
echo "我准备学习 PHP!<br>";
echo "这段话","由","多个","字符串"," 串联而成。";
?>

echo 命令显示字符串和变量

<?php
$txt1 = "Learn PHP";
$txt2 = "W3School.com.cn"
$cars = array("Volvo","BMW","SAAB");

echo $txt1;
echo "<br>";
echo "Study PHP at $txt2";
echo "<br>";
echo "My car is a {$cars[0]}";
?>

PHP print 语句

语言结构,有无括号均可使用:printprint()

print命令显示不同的字符串,包含HTML标记:

<?php
print "<h2>PHP is fun!</h2>";
print "Hello world!<br>";
print "I'm about to learn PHP!";
?>

用 print 命令显示字符串和变量

<?php
$txt1 = "Learn PHP";
$txt2 = "W3School.com.cn";
$cars = array("Volvo","BMW",SAAB");

echo $txt1;
echo "<br>";
echo "Study PHP at $txt2";
echo "<br>";
echo "My car is a {$cars[0]}";
?>
0 条回应