<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> echo.php </title>
<meta charset="UTF-8">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>
<body>
<?php
$foo = "foobar";
$bar = "barbaz";
echo "foo is $foo<br>"; // 输出foo is foobar
echo "foo is {$foo}<br>";
echo "foo is {{$foo}}<br>";
// 输出数组
$car = array("value" => "foo");
echo "this is {$car['value']} !<br>"; // 输出this is foo !
// 如果用单引号括出一个变量,则只会输出变量名称,而不是变量的值
echo 'foo is $foo<br>'; // foo is $foo
// 直接输出变量
echo $foo ."<br>"; // 输出foobar
echo $foo,$bar; // 输出foobarbarbaz
echo "<br>";
// 使用多参数输出,也就是将每个单词分开作为参数
echo 'This ', 'string ', 'was ', 'made ';
echo 'This ' . 'string ' . 'was ' . 'made ' . "<br>";
// echo 不是一个函数,因此下面的语法是错误的
//($bar) ? echo 'true' : echo 'false';
//而print 是一个函数,下面的语法正确
($bar) ? print('true'): print('false');
$myname="forway";
$yourname="admin";
?>
<br>html 中应用变量:<br>
我的名字是:<?php echo $myname ?>
<br>
你的名字是:<?php echo $yourname ?>
</body>
</html>
foo is foobar
foo is foobar
foo is {foobar}
this is foo !
foo is $foo
foobar
foobarbarbaz
This string was made This string was made
true
html 中应用变量:
我的名字是:forway
你的名字是:admin