Membuat fungsi Greeting PHP

1. Membuat fungsi-fungsi greeting pada file selamatpagi.php

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;

<html xmlns=”http://www.w3.org/1999/xhtml”&gt;
<head>

<title>Greeting</title>
</head>
<body>

<center>

<h1>
<?php
function greeting()
{
$date = date (“G : i A”);
if ($date>=0 and $date<10) {
echo “Selamat Pagi”;
} else if ($date>=10 and $date<15) {
echo “Selamat Siang”;
} else if ($date>=15 and $date<19) {
echo “Selamat Sore”;
} else if ($date>=19 and $date<00) {
echo “Selamat Malam”;
}else echo “Waktu salah)”;
}
?>
<?php greeting(); ?><br>

</h1>

<h3> Sekarang adalah

<?php

//Array Hari

$hari = date(“w”);
//Format Tanggal
$tanggal = date (“j”);
//Array Bulan
$array_bulan = array(1=>”Januari”,”Februari”,”Maret”, “April”, “Mei”, “Juni”,”Juli”,”Agustus”,”September”,”Oktober”, “November”,”Desember”);
$bulan = $array_bulan[date(“n”)];
//Format Tahun
$tahun = date(“Y”);
//Menampilkan hari dan tanggal
echo “hari $hari, tanggal $tanggal $bulan $tahun”;
?>
<br>

Waktu menunjukkan pukul
<?php
//penulisan waktu
$date = date (“G : i A”);
echo “$date WIB”;
?>
</h3>
</body>
</html>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s