Genişletilmiş Tarih Metni Sınıfı

PHP
49 lines
<?php
Class genisTarih {
var $data;
var $bol;
var $sonuc;
var $ay;
function gunu($gun){
switch ($gun){
case 1: $this->sonuc = "birinci"; break;
case 2: $this->sonuc = "ikinci"; break;
case 3: $this->sonuc = "üçüncü"; break;
case 4: $this->sonuc = "dördüncü"; break;
case 5: $this->sonuc = "beşinci"; break;
case 6: $this->sonuc = "altıncı"; break;
case 7: $this->sonuc = "yedinci"; break;
case 8: $this->sonuc = "sekizinci"; break;
case 9: $this->sonuc = "dokuzuncu"; break;
case 10: $this->sonuc = "on"; break;
case 20: $this->sonuc = "yirmi"; break;
case 30: $this->sonuc = "otuz"; break;
}
return $this->sonuc;
}
function gun($gun){
if(($gun - 30) > 0){
$this->sonuc = $this->gun(30)." ".$this->gun($gun - 30);
} elseif(($gun - 20) > 0){
$this->sonuc = $this->gun(20)." ".$this->gun($gun - 20);
} elseif(($gun - 10) > 0){
$this->sonuc = $this->gun(10)." ".$this->gun($gun - 10);
} else {
$this->sonuc = $this->gun($gun);
}
return $this->sonuc;
}
function ay($ay){
$this->ay = array('Ocak','Şubat','Mart','Nisan','Mayıs','Haziran','Temmuz','Ağustos','Eylül','Ekim','Kasım','Aralık');
$this->sonuc = $this->ay[floor($ay)-1];
return $this->sonuc;
}
function genisTarih($data){
$this->bol = explode("/", $data);
$gun = $this->gunu($this->bol[0]);
$this->sonuc = "Bugun ".$this->bol[2]." yılının ".$this->ay($this->bol[1])." ayının ".$gun." günündeyiz.";
echo ucfirst($this->sonuc);
}
}
new genisTarih(date("d/m/Y"));
?>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Çıktısı

Markdown
1 lines
Bugun 2018 yılının Haziran ayının ikinci günündeyiz.
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

 

Zamana ve Anahtara Göre Değişken Şifreleme Sınıfı

PHP
48 lines
<?php
class Sifreleyici{
var $anahtar;
function Sifreleyici($anahtar){
$this->anahtar = $anahtar;
}
function anahtardegistir($anahtar){
$this->anahtar = $anahtar;
}
function anahtarED($metin) {
$sifrele_anahtar = md5($this->anahtar);
$ctr=0;
$topla = "";
for ($i=0;$i<strlen($metin);$i++) {
if ($ctr==strlen($sifrele_anahtar)) $ctr=0;
$topla.= substr($metin,$i,1) ^ substr($sifrele_anahtar,$ctr,1);
$ctr++;
}
return $topla;
}
function sifrele($metin){
srand((double)microtime()*1000000);
$sifrele_anahtar = md5(rand(0,32000));
$ctr=0;
$topla = "";
for ($i=0;$i<strlen($metin);$i++){
if ($ctr==strlen($sifrele_anahtar)) $ctr=0;
$topla.= substr($sifrele_anahtar,$ctr,1) .
(substr($metin,$i,1) ^ substr($sifrele_anahtar,$ctr,1));
$ctr++;
}
return base64_encode($this->anahtarED($topla));
}
function coz($metin) {
$metin = $this->anahtarED(base64_decode($metin));
$topla = "";
for ($i=0;$i<strlen($metin);$i++){
$md5 = substr($metin,$i,1);
$i++;
$topla.= (substr($metin,$i,1) ^ $md5);
}
return $topla;
}
}
$c=new Sifreleyici("asd");
echo $c->sifrele("12345678");
echo $c->coz("VGoJPwM/B2ACNl8+BWhSOQ==");
?>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Çıktısı

Markdown
2 lines
VGoJPwM/B2ACNl8+BWhSOQ==
12345678
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

 

Web Sayfası Yüklenme Zamanını Bulma

PHP
33 lines
<?php
class zamanlayici{
var $baslat;
var $durdur;
var $zaman;
function zamanlayici($baslat = true){
if($baslat){
$this->baslat();
}
}
function baslat(){
$this->baslat = $this->simdi();
$this->durdur = null;
$this->zaman = null;
}
function stop(){
$this->durdur = $this->simdi();
$this->zaman = ($this->durdur - $this->baslat);
return $this->zaman;
}
function zaman_getir(){
return $this->zaman;
}
function simdi(){
list($milisaniye, $saniye) = explode(" ", microtime());
return ((float)$milisaniye + (float)$saniye);
}
}
$zamanlayici = new zamanlayici();
$contents = file_get_contents("http://www.ulusanyazilim.com");
$zaman = $zamanlayici->stop();
echo "İçerikler {$zaman} saniyede alındı.";
?>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Çıktısı

Markdown
1 lines
İçerikler 1.3313419818878 saniyede alındı.
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

 

Değişik Stillerde Türkçe Tarih Gösterimi

PHP
75 lines
<?php
class tarih_tr{
function gun_tr($gun){
switch($gun){
case 0 : $gun = "Pazar";
break;
case 1 : $gun = "Pazartesi";
break;
case 2 : $gun = "Salı";
break;
case 3 : $gun = "Çarşamba";
break;
case 4 : $gun = "Perşembe";
break;
case 5 : $gun = "Cuma";
break;
case 6 : $gun = "Cumartesi";
break;
}
return $gun;
}
function ay_tr($ay){
switch($ay){
case 1 : $ay = "Ocak";
break;
case 2 : $ay = "Şubat";
break;
case 3 : $ay = "Mart";
break;
case 4 : $ay = "Nisan";
break;
case 5 : $ay = "Mayıs";
break;
case 6 : $ay = "Haziran";
break;
case 7 : $ay = "Temmuz";
break;
case 8 : $ay = "Ağustos";
break;
case 9 : $ay = "Eylül";
break;
case 10 : $ay = "Ekim";
break;
case 11 : $ay = "Kasım";
break;
case 12 : $ay = "Aralık";
break;
}
return $ay;
}
function hazirla($stil){
if(empty($stil) or $stil>4 or $stil<1){
$stil = 4;
}
if($stil==1){
$veri = date("d")."/".date("m")."/".date("y");
}elseif($stil==2){
$veri = date("d")."/".date("m")."/".date("Y");
}elseif($stil==3){
$veri = date("d")."/".date("m")."/".date("Y")." ".$this->gun_tr(date("w"));
}elseif($stil==4){
$veri = date("d")." ".$this->ay_tr(date("n"))." ".date("Y")." ".$this->gun_tr(date("w"));
}
return $veri;
}
}
$dt = new tarih_tr;
echo $dt->hazirla(1);
echo "<br>";
echo $dt->hazirla(2);
echo "<br>";
echo $dt->hazirla(3);
echo "<br>";
echo $dt->hazirla(4);
?>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Çıktısı

Markdown
4 lines
30/05/18
30/05/2018
30/05/2018 Çarşamba
30 Mayıs 2018 Çarşamba
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

 

Sayfa Yüklenme Zamanını Göstermek ve Gizlemek

PHP
30 lines
<?php
define("SAYFA_YUKLENME_ZAMANINI_GOSTER",true);
class ZamanSayaci{
private $baslangic;
public function __construct(){
if(SAYFA_YUKLENME_ZAMANINI_GOSTER){
$sure = microtime();
$sure = explode(" ", $sure);
$sure = $sure[1] + $sure[0];
$this->baslangic = $sure;
}
}
public function al(){
if(SAYFA_YUKLENME_ZAMANINI_GOSTER == true){
$sure = microtime();
$sure = explode(" ", $sure);
$sure = $sure[1] + $sure[0];
$bitis = $sure;
$toplamsure = ($bitis - $this->baslangic);
return sprintf("Bu sayfa %f saniyede yüklendi.", $toplamsure);
}
}
}
$t = new ZamanSayaci();
$a = array();
for($i=0;$i<1000;$i++){
$a[$i] = $i;
}
echo $t->al();
?>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Çıktısı

Markdown
1 lines
Bu sayfa 0.000530 saniyede yüklendi.
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

 

İki Tarih Arasındaki Farkı Gün, Saat, Dakika ve Saniye Olarak Hesaplamak

PHP
20 lines
<?php
header('Content-Type: text/html; charset=utf-8');
date_default_timezone_set('Europe/Istanbul');
class tarihfarki{
public $tarih1, $tarih2, $a, $gun, $saat, $dakika, $saniye;
function __construct($tarih1, $tarih2){
$this->tarih1 = $tarih1;
$this->tarih2 = $tarih2;
$this->gun = intval((strtotime($this->tarih1) - strtotime($this->tarih2)) / 86400);
$this->a = ((strtotime($this->tarih1) - strtotime($this->tarih2))) % 86400;
$this->saat = intval(($this->a) / 3600);
$this->a = ($this->a) % 3600;
$this->dakika = intval(($this->a) / 60);
$this->a = ($this->a) % 60;
$this->saniye = $this->a;
}
}
$sonuc = new tarihfarki("01.01.2007 11:02:02", "20.12.2006 10:00:00");
echo $sonuc->gun . ' gün ' . $sonuc->saat . ' saat ' . $sonuc->dakika . ' dakika ' . $sonuc->saniye . ' saniye';
?>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Çıktısı

Markdown
1 lines
12 gün 1 saat 2 dakika 2 saniye
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Bonus

Bulunduğunuz Yerin Saatini Öğrenmek için https://www.google.com.tr/search?q=between+time

Zaman Makinesi Sınıfı ile Geçmiş ve Geleceğe Gitmek

PHP
52 lines
<?php
date_default_timezone_set('Europe/Istanbul');
class zamanMakinesi{
var $tarih;
var $eksilt;
var $unite;
function zamanMakinesi(){
$this->tarih = NULL;
$this->eksilt = NULL;
$this->unite = NULL;
}
function tarihler($tarih,$eksilt,$unite){
$yil = date("Y",strtotime($tarih));
$ay = date("m",strtotime($tarih));
$gun = date("d",strtotime($tarih));
$saat = date("H",strtotime($tarih));
$dakika = date("i",strtotime($tarih));
$saniye = date("s",strtotime($tarih));
if($unite=="ay") {
$yenitarih = mktime ($saat,$dakika,$saniye,$ay-$eksilt,$gun, $yil);
$yenitarih = date("d-m-Y H:i:s", $yenitarih);
} elseif( $unite=="gun") {
$yenitarih = mktime ($saat,$dakika,$saniye,$ay,$gun-$eksilt, $yil);
$yenitarih = date("d-m-Y H:i:s", $yenitarih);
} elseif ($unite=="yil") {
$yenitarih = mktime ($saat,$dakika,$saniye,$ay,$gun, $yil-$eksilt);
$yenitarih = date("d-m-Y H:i:s", $yenitarih);
} elseif( $unite=="saat") {
$yenitarih = mktime ($saat-$eksilt,$dakika,$saniye,$ay,$gun, $yil);
$yenitarih = date("d-m-Y H:i:s", $yenitarih);
} elseif ($unite=="dakika") {
$yenitarih = mktime ($saat,$dakika-$eksilt,$saniye,$ay,$gun, $yil);
$yenitarih = date("d-m-Y H:i:s", $yenitarih);
} elseif( $unite=="saniye") {
$yenitarih = mktime ($saat,$dakika,$saniye-$eksilt,$ay,$gun, $yil);
$yenitarih = date("d-m-Y H:i:s", $yenitarih);
}
else{
return false;
}
return $yenitarih;
}
}
echo date("d-m-Y H:i:s")."<br>";
$t=new zamanMakinesi;
echo $t->tarihler(date("d-m-Y H:i:s"),1,"yil")."<br>";
echo $t->tarihler(date("d-m-Y H:i:s"),-1,"ay")."<br>";
echo $t->tarihler(date("d-m-Y H:i:s"),1,"gun")."<br>";
echo $t->tarihler(date("d-m-Y H:i:s"),-1,"saat")."<br>";
echo $t->tarihler(date("d-m-Y H:i:s"),1,"dakika")."<br>";
echo $t->tarihler(date("d-m-Y H:i:s"),-1,"saniye")."<br>";
?>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Çıktısı

Markdown
7 lines
24-05-2018 03:26:01
24-05-2017 03:26:01
24-06-2018 03:26:01
23-05-2018 03:26:01
24-05-2018 04:26:01
24-05-2018 03:25:01
24-05-2018 03:26:02
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

 

Türkçe Tarih Formatlamak

PHP
22 lines
<?php
header('Content-Type: text/html; charset=utf-8');
class tr {
static function tarih($format='',$tarih=''){
$aylar = Array('Ocak','Şubat','Mart','Nisan','Mayıs','Haziran','Temmuz','Ağustos','Eylül','Ekim','Kasım','Aralık');
$gunler = Array('Pazar','Pazartesi','Salı','Çarşamba','Perşembe','Cuma','Cumartesi');
if($tarih== ''){$tarih=time();}
$ftarih = str_replace('D','#1', $format);
$ftarih = str_replace('l','#2', $ftarih);
$ftarih = str_replace('M','#3', $ftarih);
$ftarih = str_replace('f','#4', $ftarih);
$gun = $gunler[date('w', $tarih)];
$ay = $aylar[date('m', $tarih)-1];
$cikti = str_replace('#1',$gun, date($ftarih, $tarih));
$cikti = str_replace('#2',$gun, $cikti);
$cikti = str_replace('#3',$ay, $cikti);
$cikti = str_replace('#4',$ay, $cikti);
return($cikti);
}
}
echo tr::tarih('d M Y, D H:i:s');
?>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Çıktısı

JavaScript
1 lines
23 Mayıs 2018, Çarşamba 20:38:10
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

 

Tarih ve Saat Dönüştürme Sınıfı

PHP
31 lines
<?php
date_default_timezone_set('Europe/Istanbul');
class TarihYonet {
public $girilen;
public $damga;
public $tarih;
public $zaman;#YYYY-MM-DD HH:MM:SS
function __construct($girilen) {
$this->girilen = trim($girilen);
if (preg_match("/^\d{4}-\d{2}-\d{2}$/", $this->girilen)) {
$tarihDizi = explode('-', $this->girilen);
$this->tarih = $this->girilen;
$this->damga = mktime(0, 1, 1, $tarihDizi[1], $tarihDizi[2], $tarihDizi[0]);
$this->zaman = date('Y-m-d H:i:s', $this->damga);
} else if (preg_match("/^\d{4}-\d{2}-\d{2} [0-2][0-3]:[0-5][0-9]:[0-5][0-9]$/", $this->girilen)) {
$parcala = explode(' ', $this->girilen);
$tarihDizi = explode('-', $parcala[0]);
$this->zaman = $this->girilen;
$this->damga = mktime(0, 1, 1, $tarihDizi[1], $tarihDizi[2], $tarihDizi[0]);
$this->tarih = date('Y-m-d', $this->damga);
} else {
$this->damga = $this->girilen;
$this->tarih = date('Y-m-d', $this->girilen);
$this->zaman = date('Y-m-d H:i:s', $this->girilen);
}
}
}
$ornek = new TarihYonet(time());
print_r($ornek);
?>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Çıktısı

TarihYonet Object
(
    [girilen] => 1526461072
    [damga] => 1526461072
    [tarih] => 2018-05-16
    [zaman] => 2018-05-16 11:57:52
)

 

Sayfa Yüklenme Süresi

PHP
28 lines
<?php
class sayfaYuklemeSuresi{
var $baslat;
var $bitir;
function sayfaYuklemeSuresi(){
$this->baslat();
}
function baslat(){
$this->baslat = $this->zamanAl();
}
function bitir(){
$this->bitir = $this->zamanAl();
}
function yuklemeAl($format = '%01.2f'){
if(empty($this->bitir))$this->bitir();
return sprintf($format,($this->bitir - $this->baslat));
}
function zamanAl(){
$zaman = microtime();
$zaman = explode(' ', $zaman);
return $zaman[1] + $zaman[0];
}
}
$yukle = new sayfaYuklemeSuresi;
for($i=0;$i<1000000;$i++)
$a = $i * ($i/2);
echo $yukle->yuklemeAl();
?>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Çıktısı

Markdown
1 lines
0.35
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX