AdrianDevera AdrianDevera - 18 days ago 7
HTML Question

Calling PHP function in HTML

Im new to Php. Im sure this is a simple issue. I am trying to call the function getDateExpected within the tags of my html file. Id like for it to return the number as a text like below. How is this done? I see that the php script would be run using some event like a button clicked but in this case nothing is being clicked. The page is only loaded. Im aware of javascript using { } but is this possible for php or is it only meant to handle requests from a form?

<?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>

Answer

As Fred-ii- commented you need PHP tags change this

<p class="w3-large w3-center">getDateExpected(21) days left</p>

to this

<p class="w3-large w3-center"><?php getDateExpected(21);?> days left</p>

And change this

  if($date << $desired)

to this

if($date < $desired)