<?php
class check{
var $bench_start = 0;
function check(){
}
function check_int($value){
$help = (int)$value;
if(strcmp($help, $value)){
return false;
}
else{
return true;
}
}
function check_empty($value, $type = 1){
if($type == 0){
if(empty($value)){
return true;
}
else{
return false;
}
}
else{
if(!empty($value) || $value == "0"){
return true;
}
else{
return false;
}
}
}
function get_max($value_arr){
$max = $value_arr[0];
$i = 0;
$arr_index = $i;
foreach($value_arr as $val){
if($val > $max){
$max = $val;
$arr_index = $i;
}
$i++;
}
$return["arr_index"] = $arr_index;
$return["max_val"] = $max;
return $return;
}
function get_min($value_arr){
$min = $value_arr[0];
$i = 0;
$arr_index = $i;
foreach($value_arr as $val){
if($val < $min){
$min = $val;
$arr_index = $i;
}
$i++;
}
$return["arr_index"] = $arr_index;
$return["min_val"] = $min;
return $return;
}
function max($value, $max){
if($value > $max){
return false;
}
else{
return true;
}
}
function min($value, $min){
if($value < $min){
return false;
}
else{
return true;
}
}
function max_strlen($string, $max){
if(strlen($string) > $max){
return false;
}
else{
return true;
}
}
function min_strlen($string, $min){
if(strlen($string) < $min){
return false;
}
else{
return true;
}
}
function check_email($value){
$reg_exp="^([-!#\$%&'*+./0-9=?A-Z^_`a-z{|}~])+@([-!#\$%&'*+/0-9=?A-Z^_`a-z{|}~]+\\.)+[a-zA-Z]{2,6}\$";
$is_valid = eregi($reg_exp, $value);
if(!$is_valid){
return false;
}
else{
return true;
}
}
function check_plz($value, $check_strlen = 1){
$help = $value;
$first_letter = substr($value, 0, 1);
$is_null = false;
if(!strcmp($first_letter, "0")){
$is_null = true;
}
$plz= (int)$value;
if($is_null){
$plz = "0".$plz;
}
switch($check_strlen){
case 1:
if(strcmp($plz, $help) || strlen($plz) <5){
return false;
}
else{
return true;
}
break;
case 0:
if(strcmp($plz, $help)){
return false;
}
else{
return true;
}
break;
default:
echo "False type for check_strlen";
}
}
function sum($val_array = array(), $sum_val){
$sum = 0;
foreach($val_array as $val){
$sum += $val;
}
if($sum == $sum_val){
return true;
}
else{
return false;
}
}
function check_date($date){
$d = explode(".", $date);
if(strlen(@$d[2]) > 2){
@$d[2] = substr($d[2], strlen($d[2]) - 2 , 2);
}
if(checkdate(@$d[1], @$d[0], @$d[2])){
return true;
}
else{
return false;
}
}
function german_chars($string){
$string = str_replace("Ä", "Ä", $string);
$string = str_replace("Ö", "Ö", $string);
$string = str_replace("Ü", "Ü", $string);
$string = str_replace("ä", "ä", $string);
$string = str_replace("ö", "ö", $string);
$string = str_replace("ü", "ü", $string);
$string = str_replace("ß", "ß", $string);
$string = str_replace("é", "é", $string);
return $string;
}
function is_hostname($url){
// (type of stream )(domain ).(tld )
$reg_exp = "/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/)*([a-z]{1,}[\w-.]{0,}).([a-z]{2,6})$/i";
if(!preg_match($reg_exp, $url, $result)){
return false;
}
return true;
}
function is_url($url){
// (type of stream )(domain ).(tld )(scriptname or dirs )
$reg_exp = "/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/)([a-z]{1,}[\w-.]{0,}).([a-z]{2,6})(\/{1}[\w_]{1}[\/\w-&?=_%]{0,}(.{1}[\/\w-&?=_%]{0,})*)*$/i";
if(!preg_match($reg_exp, $url, $result)){
return false;
}
return true;
}
function base_convert($num, $from){
$result["binary"] = base_convert($num, $from, 2);
$result["octal"] = base_convert($num, $from, 8);
$result["decimal"] = base_convert($num, $from, 10);
$result["hex"] = base_convert($num, $from, 16);
return $result;
}
function random_nr($min = 0, $max = 100000000000000){
return (mt_rand($min, $max));
}
function random_text($prefix = "generate_random_id"){
return md5(uniqid($prefix));
}
function microtime(){
$time = microtime();
$time = explode(" ", $time);
return $time[1] + $time[0];
}
function start_benchmark(){
$GLOBALS["bench_start_time"] = check::microtime();
}
function stop_benchmark(){
$GLOBALS["bench_end_time"] = check::microtime();
$time = $GLOBALS["bench_end_time"] - $GLOBALS["bench_start_time"];
$time = explode(".", $time);
$time[1] = substr($time[1], 0, 4);
$days = 0;
$hours = 0;
$mins = 0;
$seconds = $time[0];
while($seconds > 60){
$mins++;
$seconds -= 60;
}
while($mins > 60){
$hours++;
$mins -= 60;
}
while($hours > 24){
$days++;
$hours -= 24;
}
$durability = $days." Tage ".$hours." Stunden ".$mins." Minuten ".$seconds.".".$time[1]." Sekunden";
echo "<br><b>Skriptdauer: ".$durability."</b>";
}
function debug($array, $blank=0, $echo_class=0){
$multi = false;
if(is_object($array) && !$echo_class){
echo "<b>Debug des Objekts: ".get_class($array)."</b><br>";
$multi = true;
}
if(is_array($array) && !$echo_class){
echo "<b>Debug eines Arrays</b><br>";
$multi = true;
}
if(!$multi && !$echo_class){
echo "<b>Debug einer einzelnen Variable</b><br>";
echo $array;
}
else{
$blanks = "";
for($i=0; $i<$blank; $i++){
$blanks .= " ";
}
while(list($key, $val) = each ($array)){
if(is_array($val) || is_object($val)){
if(is_object($val)){
echo $blanks.$key." => "."<b>".$val." ".get_class($val)."</b><br>";
}
else{
echo $blanks.$key." => "."<b>".$val."</b><br>";
}
debug($val, $blank+1, 1);
}
else{
echo $blanks.$key." => ".$val."<br>";
}
}
}
}
function object_info($object){
$methods = get_class_methods(get_class($object));
$vars = get_class_vars(get_class($object));
echo "<b>Übersicht über das Objekt der Klasse: ".get_class($object)."</b><br>";
echo "<b>Elternklasse :".get_parent_class($object)."</b><br>";
echo "<b>Übersicht über die Methoden der Klasse:<br></b>";
foreach($methods as $method){
echo " ".$method."<br>";
}
echo "<b>Übersicht über die Variablen der Klasse: (Varname => Defaultwert)<br></b>";
foreach($vars as $var => $val){
echo " ".$var." => ".$val."<br>";
}
}
}
?>