This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function TimeRangeRusString($time1,$time2) { | |
$diff = $time2-$time1; | |
if ($diff==0) return "0 секунд"; | |
$str = array(); | |
if ($diff>=2592000) { $h = floor($diff/2592000); $str[] = omNumber($h, array('месяц','месяца','месяцев')); $diff-=$h*2592000; } | |
if ($diff>=604800 && count($str)<1) { $h = floor($diff/604800); $str[] = omNumber($h, array('неделю','недели','недель')); $diff-=$h*604800; } | |
if ($diff>=86400 && count($str)<1) { $h = floor($diff/86400); $str[] = omNumber($h, array('день','дня','дней')); $diff-=$h*86400; } | |
if ($diff>=3600 && count($str)<1) { $h = floor($diff/3600); $str[] = omNumber($h, array('час','часа','часов')); $diff-=$h*3600; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
-(bool) luhnValidate ("number"); | |
*/ | |
function luhnValidate($string) { | |
$string = preg_replace("![^0-9]!","",$string); | |
$result = ""; | |
foreach (str_split(strrev((string) $string)) as $i => $d) { $result .= $i %2 !== 0 ? $d * 2 : $d; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function hoursDotMinutes($seconds) { | |
$h = floor($seconds/3600); | |
$seconds -= $h*3600; | |
$m = floor($seconds/60); | |
return sprintf("%02d:%02d",$h,$m); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function num2chars($n) { | |
$cs = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
$s = strlen($cs); | |
$str = ""; | |
while($n) { | |
$str = $cs{$n%$s}.$str; | |
$n = floor($n/$s); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function cidr2mask($mask){ | |
return long2ip(pow(2,32) - pow(2, (32-$mask))); | |
} | |
function mask2cidr($mask){ | |
$a=strpos(decbin(ip2long($mask)),"0"); | |
if (!$a){$a=32;} | |
return $a; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class db { | |
public $isConnected; | |
protected $datab; | |
public function __construct($username, $password, $host, $dbname, $options=array()){ | |
$this->isConnected = true; | |
try { | |
$this->datab = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $username, $password, $options); | |
$this->datab->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function object_to_array($data) { | |
if (is_array($data) || is_object($data)) { | |
$result = array(); | |
foreach ($data as $key => $value) { $result[$key] = object_to_array($value); } | |
return $result; | |
} | |
return $data; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function ev_mb_ucfirst($str) { | |
$fc = mb_strtoupper(mb_substr($str, 0, 1)); | |
return $fc.mb_substr($str, 1); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (!function_exists('getallheaders')) { | |
function getallheaders() { | |
$headers = ''; | |
foreach ($_SERVER as $name => $value) { | |
if (substr($name, 0, 5) == 'HTTP_') { | |
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 55.88846600 = current latitude | |
-- 37.44916300 = current longitude | |
SELECT Title, ROUND( 6371000 * acos( cos( radians('55.88846600') ) * cos( radians( Lat ) ) * cos( radians( Lng ) - radians('37.44916300') ) + sin( radians('55.88846600') ) * sin( radians( Lat ) ) ) ) AS distance FROM Points HAVING distance < 500 OR distance IS NULL ORDER BY distance LIMIT 1 |
OlderNewer