【发布时间】:2016-11-20 19:12:40
【问题描述】:
我是 PHP 新手。我确定这是一个简单的问题。我试图在我的 html 文件的标签中调用函数 getDateExpected。我希望它以如下文本形式返回数字。这是怎么做到的?我看到 php 脚本将使用诸如单击按钮之类的事件运行,但在这种情况下,没有单击任何内容。该页面仅加载。我知道使用 { } 的 javascript 但这对于 php 是可能的还是只是为了处理来自表单的请求?
<?php
//include "landing.php";
function getDateExpected($desired){
$date = date ("d");
if($date << $desired){
echo $desired - $date;
}else{
echo $date-$desired;
}
}
?>
<!DOCTYPE html>
<html>
<title>Coming Soon</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://www.w3schools.com/lib/w3.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Raleway">
<style>
body,h1 {font-family: "Raleway", sans-serif}
body, html {height: 100%}
.bgimg {
background-image: url('obg.png');
min-height: 100%;
background-position: center;
background-size: cover;
}
</style>
<body>
<div class="bgimg w3-display-container w3-animate-opacity w3-text-white">
<div class="w3-display-topleft w3-padding-large w3-xlarge">
Potion
</div>
<div class="w3-display-middle">
<h1 class="w3-jumbo w3-animate-top">COMING SOON</h1>
<hr class="w3-border-grey" style="margin:auto;width:40%">
<p class="w3-large w3-center">getDateExpected(21) days left</p>
</div>
<div class="w3-display-bottomleft w3-padding-large">
<a href="http://www.twitter.com/" target="_blank">Adrian</a>
</div>
</div>
</body>
</html>
【问题讨论】:
-
function getDateExpected($desired){ $date = date ("d"); if($date << $desired){ echo $desired - $date; }else{ echo $date-$desired; } }那么所有这些调用/定义在哪里? -
<p class="w3-large w3-center">getDateExpected(21) days left</p>函数名周围没有php标签,如果你打算在它的位置执行它。 -
您需要将php代码包装在php标签中-
<p class="w3-large w3-center"><?php getDateExpected(21); ?> days left</p> -
if($date << $desired)- 那些<<不会做你期望他们做的事情。 -
还要确保您在安装了网络服务器并使用正确的扩展名来解析 php 指令的 php 环境下运行它。
标签: php html function echo call