Location: PHPKode > projects > RosInfo > rosinfo-1.30/include/functions.php
<?
function convert_alphabet($string)
{
    $array = preg_split('//', $string, -1, PREG_SPLIT_NO_EMPTY);
    $str = "";
    foreach ($array as $char)
    {
	$i = ord($char);
	if (($i >= 48) && ($i <=57) || ($i >= 65 && $i <= 90) || ($i >= 97 && $i <= 122))
	    $str .= $char;
	else
	    $str .= "_".$i."_";	
    }
    return $str;
}

function convert_alphabet_rev($string)
{
    $arr = explode("_", $string);
    $convert = false;
    $str = "";
    foreach ($arr as $part)
    {
	if ($convert)
	    $str .= chr($part);
	else
	    $str .= $part;
	$convert = !$convert;
    }
    return $str;
}

function isIPInSubnets($ip, $subnets)
{
  foreach ($subnets as $subnet)
  {
    if (isIPIn($ip, $subnet))
      return true;
  }
  return false;
}

function isIPIn($ip, $subnet) {
  
  $ip_arr = explode('/', $subnet);
  
  $ip2 = ip2long($ip);
  $rede = ip2long($ip_arr[0]);
  $mask = ~((1 << (32 - $ip_arr[1])) - 1);

  //AND 
  $res = $ip2 & $mask;
  
  return ($res == $rede);
}

function getmicrotime() {  
    $temparray = split(" ",microtime());  
    $returntime = $temparray[0] + $temparray[1];  
    return $returntime;  
}

function echo_div($string, $type="info")
{
  echo "<div class=\"post\"><br/>";
  
  switch ($type)
  {
    case "info":
      echo "<h4>Information</h4>";
      break;
    case "error":
      echo "<h4>Error</h4>";
      break;
  }

  echo "<p>$string</p>";
  echo "</div>";
}

function echo_die($string)
{
  echo_div($string, "error");
  die;
}
?>
Return current item: RosInfo