<?

//$lasterror=0;

error_reporting(E_ERROR);

//function userErrorHandler ($errno, $errmsg, $filename, $linenum, $vars) {
//  if ($errno<8) {$lasterror=$errno;}
//}

//$old_error_handler=set_error_handler("userErrorHandler");

function getin($gi_data,$gi_begin,$gi_end)
{
	$gi_pos1=strpos($gi_data,$gi_begin);
	if ($gi_pos1 === false)	{return "";}
	$gi_data1 = substr($gi_data,$gi_pos1+strlen($gi_begin));
	$gi_pos2=strpos($gi_data1,$gi_end);
	if ($gi_pos2 === false)	{$gi_pos2=strlen($gi_data);}
	return substr($gi_data1,0,$gi_pos2);
}

function replace($str_src,$str_find,$str_replace)
{
  $rpl_s=$str_src; $rpl_b=0; $rpl_pos=0;

  while ($rpl_b==0)
  {
    $rpl_pos=strpos($rpl_s,$str_find,$rpl_pos);
    if ($rpl_pos>0)
      $rpl_s=substr_replace($rpl_s,$str_replace,$rpl_pos,strlen($str_find));
    else
      $rpl_b=1;
  }

  return $rpl_s;
}

function padl($str,$icount,$achar)
{
  $p_s=$str;
  while (strlen($p_s)<$icount) $p_s="$achar$p_s";
  return $p_s;
}

function loadfile($filename)
{
  $of_file=fopen($filename, "rb");
  while (!feof($of_file))
  { $of_filedata .= fread($of_file, 32767);
    if (strlen($of_filedata)==0) return "";}
  fclose($of_file);
  return $of_filedata;
}

function savefile($filename,$savedata)
{
  $sf_file=fopen($filename, "wb");
  fwrite($sf_file, $savedata);
  fclose($sf_file);
}

function getext($str)
{
  return preg_replace("~^(.*)\.([^\.]+)|()$~","\\2\\3",$str);
}

function getnoext($str)
{
  $gne_s=preg_replace("~^(.*)\.([^\.]+)|()$~","\\2\\3",$str);
  return substr_replace($str,"",strlen($str)-strlen($gne_s)-1,strlen($gne_s)+1);
}

function filescount($path)
{
  $fc_handle=opendir($path);
  $fc_i=0;
  while ($fc_file = readdir($fc_handle))
  {
    if ($fc_file!=="." and $fc_file!==".." and $fc_file!=="name.txt" and $fc_file!=="img.jpg" and getext($fc_file)!=="txt")
    {
      $fc_i=$fc_i+1;
    }
  }
  closedir($fc_handle);
  return $fc_i;
}

function antihack($str)
{
  $ah_s=replace($str,"\\","");
  $ah_s=replace($ah_s,"/","");
  $ah_s=replace($ah_s,"|","");
  $ah_s=replace($ah_s,"..","");
  return $ah_s;
}
?>
