Yaşanmış Gün Hesabı Uygulama:11

<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Yaş Hesaplama</title>
<style>label{float:left;width:40px; font-weight:bold;}div{ width:200px; float:left; height:230px; border:1px solid #333; padding-left:10px; padding-right:10px;} input[type=submit]{ width:200px; font-weight:bold;} p{ font-weight:bold; color:#009;} input[type=text] { border-color:#CCC;}</style>
</head>

<body>
<div>
<p>Doğum tarihinizi giriniz:</p>
<form action=”yashesaplama.php” name=”yashesapla” method=”post”>
<label for=”gun”>Gün:</label>
<input type=”text” name=”gun” /><br />
<label for=”ay”>Ay:</label>
<input type=”text” name=”ay” /><br />
<label for=”yil”>Yıl:</label>
<input type=”text” name=”yil” /><br />
<input type=”submit” name=”hesapla” value=”hesaplama” />
</form>
<?php
if(isset($_POST[‘hesapla’]))
{
//Yılın hangi ayında kaç gün olduğunun bir diziye kaydedilmesi
$gunler=array(1=>31,2=>28,3=>31,4=>30,5=>31,6=>30,7=>31,8=>31,9=>30,10=>31,11=>30,12=>31);
//toplam geçen günün sayısını ve bugünün değerini tutacak değişkenin ayarlanması
$toplam_gun=0;
$bugun = date(“d.m.Y”);
$bu_yil=explode(“.”,$bugun);
//doğduğu günden doğduğu yılın sonuna kadar geçen gün hesabı
for($i=$_POST[‘ay’];$i<=12;$i++)
$toplam_gun=$toplam_gun+$gunler[$i+1];
$toplam_gun=$toplam_gun+($gunler[$_POST[‘ay’]]-$_POST[‘gun’]);
//bu yılın bugüne kadar geçen gün sayısı hesabı
for($i=1;$i<$bu_yil[1];$i++)
$toplam_gun=$toplam_gun+$gunler[$i];
$toplam_gun=$toplam_gun+$bu_yil[0];
//doğum yılı ve bu yıl hariç aradaki yılların geçen gün hesabı
$toplam_gun=$toplam_gun+(365*($bu_yil[2]-$_POST[‘yil’]-1));
//artık yıllardan gelen günlerin hesabı
for($i=$bu_yil[2];$i>=$_POST[‘yil’];$i–)
if($i%4==0)
$toplam_gun++;
//artık yılın şubat ayında doğmuşsa bir eksiltme
if($_POST[‘yil’]%4==0&&$_POST[‘ay’]>2)
$toplam_gun–;
//sonucun ekrana yazdırılması
echo ‘<p style=”color:red;”>Doğduğunuz günden bugüne kadar’.$toplam_gun.’ gün yaşadınız. </p>’;
}

?>
</div>
</body>
</html>

Yorum bırakın