En basit şekilde; function getStrBetween($str,$from,$to){ return split(‘['.$from.''.$to.']‘, $str); } Daha kesin sonuçlar almak, bazı özel karakterler için regex kodları ile uğraşmak istemiyorsak; function getStringBetween($str,$from,$to){ $sub = substr($str, strpos($str,$from)+strlen($from),strlen($str)); return substr($sub,0,strpos($sub,$to)); } veya function getBetween($content,$start,$end){ $r = explode($start, $content); if (isset($r[1])){ $r = explode($end, $r[1]); return $r[0]; } return ”; }
Category: Web
Elapsed Time Bilgisi
<?php function elapsedTime($startTime = ”, $endTime = ”,$format=”SECONDS”,$decimals = 4) { if (!$startTime){ return ”; } if (!$endTime){ $endTime = microtime(); } list($startMicroSecond, $startSecond) = explode(‘ ‘, $startTime); list($endMicroSecond, $endSecond) = explode(‘ ‘, $endTime); if($format){ $format = strtoupper($format); } if($format == ‘SECONDS’){ $timeVal = number_format((($endMicroSecond + $endSecond) – ($startMicroSecond + $startSecond)),$decimals).” SECONDS”; } else if($format […]
Link Düzenleyici
<?php if (! defined(‘BASEPATH’)) exit(‘No direct script access allowed’); function link($q) { $q = str_replace(”,’ ’,$q); $q = str_replace(‘!’,’!’,$q); $q = str_replace(“‘”,’"’,$q); $q = str_replace(‘#’,’#’,$q); $q = str_replace(‘$’,’$’,$q); $q = str_replace(‘%’,’%’,$q); $q = str_replace(‘&’,’&’,$q); $q = str_replace(“‘”,’'’,$q); $q = str_replace(‘(‘,’(’,$q); $q = str_replace(‘)’,’)’,$q); $q = str_replace(‘*’,’*’,$q); $q = str_replace(‘+’,’+’,$q); $q = str_replace(‘,’,’,’,$q); $q = str_replace(‘-’,’-’,$q); $q […]
Linux Kullanıcı Hesabı İşlemleri
<?php $groupname = “”; $username = “”; $password = “”; $home = “”; // /var/www/$username function createUser($groupname, $username, $home, $password){ exec(“mkdir ” . $home); exec(“useradd ” . $username); exec(“groupadd ” . $groupname); exec(“passwd ” . $username); exec(“gpasswd -a ” . $username . “” . $groupname); exec(“chown –R ” . $username . “” . $home); exec(“chgrp […]
Random Parola Oluşturucu
<?php if (! defined(‘BASEPATH’)) exit(‘No direct script access allowed’); function pass_generator($amount) { $keyset = “ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789″; $randkey = “”; for ($i=0; $i<$amount; $i++){ $randkey .= substr($keyset, rand(0, strlen($keyset)-1), 1); } return $randkey; } ?>
Domain Ping
<?php $ping = exec(“ping 127.0.0.1″); print($ping); ?> Eğer, exec komutu çalışmazsa şu yöntemi de kullanabilirsiniz: <?php function pingDomain($domain, $port, $timeout, &$message){ $file = fsockopen ($domain, $port, $errno, $errstr, $timeout); $status = 0; $message = $message == null ? $message = array() : $message; if (!$file){ $status = -1; $m = “ping $domain:$port -> status:$status (errno:$errno […]
Associative Array Sum
<?php $data = array( 0 => array( ‘event’ => ‘Conference’, ‘budget’ => 3700, ), 1 => array( ‘event’ => ‘Conference’, ‘budget’ => 500, ), 2 => array( ‘event’ => ‘Showroom’, ‘budget’ => 1000, ), 3 => array( ‘event’ => ‘Mission Chez client’, ‘budget’ => 2000, ), 4 => array( ‘event’ => ‘Séminaire’, ‘budget’ => 700, […]
Timezone
<?php function get_time($zone_key){ $tz = new DateTimeZone($zone_key); $data = new DateTime(date(“Y-m-d H:i:s”)); $data->setTimezone($tz); //$data = new DateTime(date(“Y-m-d 00:00:00″),$tz); return $data->format(“r”); } if (!empty($_POST)){ echo get_time($_POST["timezone"]); } $zones = timezone_identifiers_list(); ?> <form action=”” method=”post”> <select name=”timezone”> <?php foreach ($zones as $key) { ?> <option value=”<?=$key;?>”><?=$key;?></option> <?php } ?> </select> <input type=”submit” value=”Select” /> </form>
cURL Nedir?
En basit anlamda cURL PHP’de daha sayfa işlenirken sayfaya veri çekmeye yarar. Örnek olarak bunu bot veya webservis yapımında kullanabiliriz. Tabi bu özelliği kullanabilmek için php.ini dosyanızda php_curl.php özelliği aktif olmak zorunda. Kod Örneği: $temp = array(“a”=>1, “b”=>2); $postdata = http_build_query($temp); $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, true); //POST Metoduyla verileri gönder curl_setopt($ch, CURLOPT_HEADER, false); //Serverdan […]
Sef Link Fonksiyonu
function permalink($string) { $find = array(‘Ç’, ‘Ş’, ‘Ğ’, ‘Ü’, ‘İ’, ‘Ö’, ‘ç’, ‘ş’, ‘ğ’, ‘ü’, ‘ö’, ‘ı’, ‘+’, ‘#’); $replace = array(‘c’, ‘s’, ‘g’, ‘u’, ‘i’, ‘o’, ‘c’, ‘s’, ‘g’, ‘u’, ‘o’, ‘i’, ‘plus’, ‘sharp’); $string = strtolower(str_replace($find, $replace, $string)); $string = preg_replace(“@[^A-Za-z0-9\-_\.\+]@i”, ‘ ‘, $string); $string = trim(preg_replace(‘/\s+/’, ‘ ‘, $string)); $string = str_replace(‘ […]