date_default_timezone_set(‘Europe/Istanbul’); $first_day_of_the_week = ‘Monday’; $start_of_the_week = strtotime(“Last $first_day_of_the_week”); if (strtolower(date(‘l’)) === strtolower($first_day_of_the_week)){ $start_of_the_week = strtotime(‘today’); } $end_of_the_week = $start_of_the_week + (60 * 60 * 24 * 7) – 1; $date_format = ‘d-M-Y l H:i:s’; echo date($date_format, $start_of_the_week); echo “<br>”; echo date($date_format, $end_of_the_week);
Category: Php
Dosya Adı Olmadan Dizin Bilgisini Almak
$file = basename($_SERVER['REQUEST_URI']); $requestPath = “..” . $_SERVER['REQUEST_URI']; $requestPath = str_replace($file, “”, $requestPath);
Phpmailer Gmail Ayarları
include ‘phpmailer/class.phpmailer.php’; $this->mail = new PHPMailer(); $this->mail->SMTPAuth = true; $this->mail->Host = ‘smtp.gmail.com’; $this->mail->Port = 465; $this->mail->SMTPSecure = ‘tls’; $this->mail->Username = ‘user@gmail.com’; $this->mail->Password = ‘password’; $this->mail->SetFrom(“noreply@yourdomain.com”, ‘Name’); $this->mail->AddAddress($to,$name); $this->mail->CharSet = ‘UTF-8′; $this->mail->Subject = $subject; $this->mail->MsgHTML($html_message); if($this->mail->Send()) { return json_encode(array(‘status’=>1,’message’=>’Success’)); } else { return json_encode(array(‘status’=>0,’message’=>$this->mail->ErrorInfo)); }
Phpmailer Ayarları
include ‘phpmailer/class.phpmailer.php’; $this->mail = new PHPMailer(); $this->mail->IsSMTP(); $this->mail->SMTPAuth = true; $this->mail->Host = ‘mail.yourdomain.com’; $this->mail->Port = 587; $this->mail->SMTPSecure = ‘tls’; $this->mail->Username = ‘user@yourdomain.com’; $this->mail->Password = ‘password’; $this->mail->SetFrom(“noreply@yourdomain.com”, ‘Name’); $this->mail->AddAddress($to,$name); $this->mail->CharSet = ‘UTF-8′; $this->mail->Subject = $subject; $this->mail->MsgHTML($html_message); if($this->mail->Send()) { return json_encode(array(‘status’=>1,’message’=>’Success’)); } else { return json_encode(array(‘status’=>0,’message’=>$this->mail->ErrorInfo)); }
Multidimensional Array Diff
function array_diff_assoc_recursive($array1, $array2){ foreach($array1 as $key => $value){ if(is_array($value)){ if(!isset($array2[$key])){ $difference[$key] = $value; }else if(!is_array($array2[$key])){ $difference[$key] = $value; }else{ $new_diff = array_diff_assoc_recursive($value, $array2[$key]); if($new_diff != FALSE){ $difference[$key] = $new_diff; } } }else if(!isset($array2[$key]) || $array2[$key] != $value){ $difference[$key] = $value; } } return !isset($difference) ? 0 : $difference; }
TC Kimlik Doğrulama Fonksiyonu
function validateTcNo($tcNo){ if(strlen($tcNo) == 11){ $x = str_split($tcNo); $valid1=((7*($x[0]+$x[2]+$x[4]+$x[6]+$x[8]) – ($x[1]+$x[3]+$x[5]+$x[7]))%10) == $x[9]; $valid2=(($x[0]+$x[1]+$x[2]+$x[3]+$x[4]+$x[5]+$x[6]+$x[7]+$x[8]+$x[9])%10) == $x[10]; return $valid1 && $valid2; }else{ return false; } }
PDO Database Class
class database { private $dbName = null, $dbHost = null, $dbPass = null, $dbUser = null; private static $instance = null; private function __construct($dbDetails = array()) { // Please note that this is Private Constructor $this->dbName = $dbDetails['db_name']; $this->dbHost = $dbDetails['db_host']; $this->dbUser = $dbDetails['db_user']; $this->dbPass = $dbDetails['db_pass']; // Your Code here to connect to database […]
UTF-16 Karakterleri UTF-8 Karaktere Dönüştürme Fonksiyonu
function utf16_to_utf8($str) { $c0 = ord($str[0]); $c1 = ord($str[1]); if ($c0 == 0xFE && $c1 == 0xFF) { $be = true; } else if ($c0 == 0xFF && $c1 == 0xFE) { $be = false; } else { return $str; } $str = substr($str, 2); $len = strlen($str); $dec = ”; for ($i = 0; […]
Memcache Kullanımı
Öncelikle buradan cache library dosyasını indiriyoruz. Daha sonra php tarafında şu kodları yazıyoruz: require_once (‘cache.php’); $memcache = new Cache(); if (($result = $memcache->get(‘cache_key’)) !== FALSE){ echo $result; }else{ $memcache->set(‘cache_key’, “return_text”, 0, 20); echo “return_text”; }
Klasör Altındaki Dosyaları Listeleme
1. Yol: $path=”../log/”; if(is_dir($path)){ if($open_path = opendir($path)){ while($file = readdir($open_path)){ echo ‘<a href=”‘ . $path . “” . $file . ‘”>’ . $file . ‘</a><br>’; } closedir($open_path); } } 2. Yol: $path = ‘../log/’; if(is_dir($path)){ $file_list = glob($path . “*.txt”); foreach($file_list as $key => $value){ $filename = str_replace($path, “”, $value); echo $filename; } }