我正在使用 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 之上,但该站点再次中断。
谢谢你。