download this file: func.misc.php view text/plain: func.misc.php file encoding: EUC-KR [goback]
<?php
##
## this file name is 'func.misc.php'
##
## misc functions
##
## [author]
##  - Chilbong Kim<san2(at)linuxchannel.net>
##
## [changes]
##  - 2009.09.08 : add print_ms(), runtime()
##  - 2003.06.14 : add ip2base(), base2ip()
##  - 2003.04.14 : new build
##
## [references]
##
## [usage]
##
## [example]
##

function get_microtime($_start$_end$d=4)
{
  
$end explode(' '$_end);
  
$start explode(' '$_start);

  return 
sprintf("%.${d}f", ($end[1]+$end[0]) - ($start[1]+$start[0]));
}

function 
print_ms($start=0)
{
  global 
$_start;

  if(!
$start$start $_start;

  echo 
get_microtime($start,microtime(),2);
}

function 
print_microtime($_start$_end)
{
  
$total get_microtime($_start,$_end);
  
$sql   get_microtime(__SQLSTART__,__SQLEND__);
  
$tmpl  get_microtime(__TMPLSTART__,$_end);
  
$init  $time['total'] - $time['sql'] - $time['tmpl'];

  echo <<<__EOP__
\n<P><PRE>
 initial read = 
$init
 sql get time = 
$sql
 tmpl parsing = 
$tmpl
total execute = 
$total seconds
</PRE>
__EOP__;

  return;
}

function 
ip2base($ipv4='')
{
  if(!
$ipv4$ipv4 $_SERVER['SERVER_ADDR'];

  
//$i = explode('.',$ipv4);
  //return ($i[0]*16777216 + $i[1]*65536 + $i[2]*256 + $i[3]);

  
return sprintf('%u',ip2long($ipv4));
}

function 
base2ip($base)
{
  
/***
  $a = ($base / 16777216) % 256;
  $b = ($base / 65536) % 256;
  $multi = floor($base / 256);
  $c = $multi % 256;
  $d = $base - ($multi * 256); // or fmod($base,256)
  return $a.'.'.$b.'.'.$c.'.'.$d;
  ***/

  
return long2ip($base);
}

## http://dbforums.com/arch/150/2002/7/424177
##
function mysql_password($pass)
{
  
$nr 1345345333;
  
$add 7;
  
$nr2 0x12345671;
  
$size strlen($pass);

  for(
$i=0;$i<$size;$i++)
  {
    
/* skipp space in password */
    
if($pass[$i] == ' ' || $pass[$i] == '\t') continue;
    
$tmp ord($pass[$i]);
    
$nr ^= ((($nr 63)+$add)*$tmp) + ($nr << 8);
    
$nr2 += ($nr2 << 8) ^ $nr;
    
$add += $tmp;
  }

  
$result1 $nr & ((<< 31) -1); /* Don't use sign bit (str2int) */
  
$result2 $nr2 & ((<< 31) -1);
  
$result sprintf('%08x%08x',$result1,$result2);

  return 
$result;
}

function 
runtime($term$lang='kr')
{
  
$l['kr'] = $l['ko'] = array('ÃÊ','ºÐ','½Ã°£','ÀÏ','´Þ');
  
$l['en'] = array('seconds','minutes','hours','days','months');
  
$l['short'] = array('sec','m','h','d','mon');

  
$months = (int)($term 2592000);
  
$term   = (int)($term 2592000);
  
$days   = (int)($term 86400);
  
$term   = (int)($term 86400);
  
$hours  = (int)($term 3600);
  
$term   = (int)($term 3600);
  
$mins   = (int)($term 60);
  
//$secs  = (int)($term % 60);

  
$months $months $months.$l[$lang][4].' ' '';
  
$days $days $days.$l[$lang][3].' ' '';
  
$hours $hours $hours.$l[$lang][2].' ' '';
  
$mins $mins $mins.$l[$lang][1] : '';
  
//$secs .= $l[$lang][0];

  
$r $months.$days.$hours.$mins;

  return (
$r $r '0'.$l[$lang][0]);
}

?>