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 | |
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 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 | |
/* | |
-(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 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; } |
NewerOlder