我正在使用WAMP来运行本地PHP / Apache服务器。我正在尝试使用HTML标签回显行的多种方法,但网站中断。这是我的代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
$name = 'John';
$months = array('January', 'February', 'March');
echo "<p>$name;</p>";
?>
<p><?php echo "Hello World!";?></p>
<p><?php echo "My name is " . $name . ", nice to meet you.";?></p>
<?php
echo "<p>Hi again, my name is " . $name . ".</p>";
?>
<?php
foreach ($months as $current_month) {
echo "<li>$current_month</li>";
}
?>
</body>
</html>
浏览器输出
$name;
"; ?>
Hi again, my name is " . $name . ".
"; ?>
我也尝试将php代码放在Doctype之上,但网站再次中断。
谢谢。
答案 0 :(得分:0)
你不能像你一样编写代码。例如:
<p>echo $name;</p>;
是完全错误的,应该这样写:
echo "<p>$name</p>";