1.
Buat fungsi countdown
untuk menghitung mundur
tanggal dan mengembalikan nilai
integer selisih hari.
Argumen dari fungsi
ini adalah string tanggal. Misal tanggal sekarang adalah
10/04/2010 (dari sistem)
dan argumen yang diberikan 15/04/2010 maka fungsi akan mengembalikan
nilai 5 (selisih tanggal).
Sintaks
<!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" xml:lang="en"
lang="en">
<head> <title>Fungsi
Countdown</title>
</head>
<body background="s.jpg">
<form name="tanggal"
method="post" action="<?php $_SERVER['PHP_SELF'];?>"
onsubmit="(this)">
<p align="left"><? echo
$status;?></p>
<table width="420"
border="6" align="left" background="1.jpg"
rules="groups" cellpadding="1"
cellspacing="1">
<tr>
<td
width="40"> </td>
<td align="center"><font
size="6" face="showcard gotic" >Fungsi
Countdown</font></td>
</tr>
<tbody >
<tr><td
width="40"> </td><td><font
size="4"
face="calibri">Tanggal</font></td></tr>
<tr><td
width="40"> </td><td><input
type="text" name="tggl" size="50"
id="tggl" /></td></tr>
<tr><td
width="40"> </td><td><font
size="4"
face="calibri">Bulan</font></td></tr>
<tr><td
width="40"> </td><td><input
type="text" name="bulan" size="50"
id="bulan" /></td></tr>
<tr><td
width="40"> </td><td><font
size="4" face="calibri">Tahun</font></td></tr>
<tr><td
width="40"> </td><td><input
type="text" name="tahun" size="50"
id="tahun" /></td></tr>
<tr><td
colspan="2"align="center"><font size="2"
face="calibri" >Masukkan Tanggal(bukan Tgl
sekarang)</font></td></tr>
<tr><td width="40"> </td><td><input
name="submit" type="submit" value="Enter"
/></td></tr>
<tr><td
width="40"> </td><td><input
name="reset" type="reset" value="Cencel"
/></td></tr>
</table>
</form>
<?php $tgl = (int) $_POST["tggl"];
?>
<?php $bln = (int) $_POST["bulan"];
?>
<?php $thn = (int) $_POST["tahun"];
?>
<?php
countdown($thn, $bln, $tgl);
function countdown($year, $month, $day)
{
// make a unix timestamp for the given date
$the_countdown_date = mktime($hour, $minute, 0,
$month, $day, $year, -1);
// get current unix timestamp
$today = time();
$difference = $today - $the_countdown_date ;
if ($difference < 0) $difference = 0;
$days_left = floor($difference/60/60/24);
$hours_left = floor(($difference -
$days_left*60*60*24)/60/60);
$minutes_left = floor(($difference -
$days_left*60*60*24 - $hours_left*60*60)/60);
// OUTPUT
echo "Tanggal hari ini ".date("F
j, Y, g:i a")."<br/>";
echo "Tanggal countdown ".date("F
j, Y, g:i a",$the_countdown_date)."<br/>";
echo "Selisih".$days_left." hari
".$hours_left." jam ".$minutes_left." menit";
}
?>
</body>
</html>
Tampilan
2.
Buat aplikasi pengolahan data berbasis file seperti
diperlihatkan pada Gambar Spesifikasinya: aplikasi mampu mengambil masukan data
dan menyimpan ke file, serta menampilkan hasilnya ke browser.
Sintaks
<!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"
xml:lang="en" lang="en">
<head>
<title>Aplikasi Pengolahan Data Berbasis File</title>
</head>
<body background="1.jpg">
<h2>Aplikasi Pengolahan Data Berbasis File</h2>
<form action="<?php $_SERVER['PHP_SELF'];?>"
method="post">
<table border=0>
<tr>
<td width=100>Nama :</td>
<td><input type="text" name="nama"
/></td>
</tr>
<tr>
<td>Alamat :</td>
<td><input type="text" name="alamat"
/></td>
</tr><tr><td> </td>
</tr>
<tr>
<tr>
<td> </td>
<td><input type="submit" value="Enter"
/></td>
</tr>
</table>
</form>
<hr />
<?php
$fl = 'alamat.txt';
if (isset($_POST['nama']) && $_POST['nama'] &&
isset($_POST['alamat']) && $_POST['alamat'] ) {
$dt = $_POST['nama'] . '#' . $_POST['alamat'] . "n";
file_append_contents($fl, $dt);
}
$arr = file($fl);
?>
<table border=1 cellspacing=1 cellpadding=1>
<tr>
<th width=10>No.</th><th width=200>Nama</th><th
width=200>Alamat
</th>
</tr>
<?php
$i = 1;
foreach ($arr as $val) {
$d = explode('#', $val);
?>
<tr>
<td><?php echo $i;?></td>
<td><?php echo $d[0];?></td>
<td><?php echo $d[1];?></td>
</tr>
<?php
$i++;
}
?>
</table>
<?php
function file_append_contents($filename, $data) {
$olddata = file_get_contents($filename);
return file_put_contents($filename, $olddata.$data);
}
?>
</body>
</html>
0 komentar:
Posting Komentar