<?php
echo "<h2>PHP is fun!</h2>";
echo(123);
echo "<br>";
echo("我爱php");
echo "<br>";
echo "Hello world!<br>";
echo "I'm about to learn PHP!<br>";
echo "This", " string", " was", " made", " with multiple parameters.";
?>
效果:
PHP is fun!
123
我爱php
Hello world!
I'm about to learn PHP!
This string was made with multiple parameters.
3.显示变量,下面的例子展示如何用 echo 命令来显示字符串和变量;
<?php
$txt1="Learn PHP";
$txt2="W3School.com.cn";
$cars=array("Volvo","BMW","SAAB");
echo $txt1;
echo "<br>";
echo "Study PHP at $txt2 <br />";
echo "My car is a {$cars[0]}";
?>
效果:
Learn PHP
Study PHP at W3School.com.cn
My car is a Volvo
<?php
print "<h2>PHP is fun!</h2>";
print "Hello world!<br>";
print "I'm about to learn PHP!";
?>
效果:
PHP is fun!
Hello world!
I'm about to learn PHP!
3.显示变量,下面的例子展示如何用 print 命令来显示字符串和变量:
<?php
$txt1="Learn PHP";
$txt2="W3School.com.cn";
$cars=array("Volvo","BMW","SAAB");
print $txt1;
print "<br>";
print "Study PHP at $txt2 <br>";
print "My car is a {$cars[0]}";
?>
效果:
Learn PHP
Study PHP at W3School.com.cn
My car is a Volvo