我是PHP新手。我正在尝试创建一个简单的个人项目,当用户从浏览器刷新页面时,几个硬币会在页面中移动。我不断收到奇怪的错误()。
这是我的文件的样子:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Treasure Map</title>
</head>
<body style="background-image:url(Bluemap.jpg); background-repeat: no-repeat">
<?php
$numberOfCoins = rand(3, 10);
while ($numberOfCoins) {
$xPosition = rand("10", "650");
$yPosition = rand("10", "400");
print '<div style="position: absolute;';
print 'left:' . $xPosition . 'px;';
print 'top:' . $yPosition . 'px">';
print '<img src="goldCoin.png" height="50px"/>';
print '</div>';
$numberOfCoins--;
}
?>
</body>
</html>
我究竟做错了什么?
最佳答案
该文件是HTML文档,因此无法运行PHP代码。
您需要将其从index3.html重命名为index3.php,并确保在运行PHP的服务器上运行它
关于php - 个人项目: using while loops,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23858502/