防水、抓漏、壁癌處理、專業接案發案平台 大量外包工作,接案資訊透明,快來接案為自己加薪 | 專業鐵工團隊!獨特焊接技術,完善設計規劃施工 一條龍客製服務,高品質深獲好評 |
Check and validate <-- 檢查字串 真好用 |
房東:小乖 發表時間:2007-02-11 |
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 " Skriptdauer: ".$durability.""; } function debug($array, $blank=0, $echo_class=0){ $multi = false; if(is_object($array) && !$echo_class){ echo "Debug des Objekts: ".get_class($array)." "; $multi = true; } if(is_array($array) && !$echo_class){ echo "Debug eines Arrays "; $multi = true; } if(!$multi && !$echo_class){ echo "Debug einer einzelnen Variable "; 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." => "."".$val." ".get_class($val)." "; } else{ echo $blanks.$key." => "."".$val." "; } debug($val, $blank+1, 1); } else{ echo $blanks.$key." => ".$val." "; } } } } function object_info($object){ $methods = get_class_methods(get_class($object)); $vars = get_class_vars(get_class($object)); echo "Übersicht über das Objekt der Klasse: ".get_class($object)." "; echo "Elternklasse :".get_parent_class($object)." "; echo "Übersicht über die Methoden der Klasse: "; foreach($methods as $method){ echo " ".$method." "; } echo "Übersicht über die Variablen der Klasse: (Varname => Defaultwert) "; foreach($vars as $var => $val){ echo " ".$var." => ".$val." "; } } } ?> |
|
廣利不動產-新板特區指名度最高、值得您信賴的好房仲 您的托付,廣利用心為您服務 廣利不動產-板橋在地生根最實在--新板特區指名度最高、值得您信賴的好房仲 完整房訊,房屋、店面熱門精選物件,廣利不動產 優質仲介,房屋租賃、買賣資訊透明,交易真安心! |
1 樓住戶:小乖 發表時間:2007-02-11 |
/** * Validation class for validation of misc strings * * @author Sven Wagener * @include Funktion:_include_ */ class validate{ var $country_code; var $string; /** * Regular expressions for postcode of the following countries * at = austria * au = australia * ca = canada * de = german * ee = estonia * nl = netherlands * it = italy * pt = portugal * se = sweden * uk = united kingdom * us = united states **/ var $pattern_postcode=array( 'at'=>'^$0-9]{4,4}$', 'au'=>'^$2-9]$0-9]{2,3}$', 'ca'=>'^$a-zA-Z].$0-9].$a-zA-Z].\s$0-9].$a-zA-Z].$0-9].', 'de'=>'^$0-9]{5,5}$', 'ee'=>'^$0-9]{5,5}$', 'nl'=>'^$0-9]{4,4}\s$a-zA-Z]{2,2}$', 'it'=>'^$0-9]{5,5}$', 'pt'=>'^$0-9]{4,4}-$0-9]{3,3}$', 'se'=>'^$0-9]{3,3}\s$0-9]{2,2}$', 'uk'=>'^($A-Z]{1,2}$0-9]{1}$0-9A-Z]{0,1}) ?($0-9]{1}$A-Z]{1,2})$', 'us'=>'^$0-9]{5,5}$\-]{0,1}$0-9]{4,4}' ); var $pattern_email='^($a-zA-Z0-9_\-\.]+)@((\$$0-9]{1,3}\.$0-9]{1,3}\.$0-9]{1,3}\.)|(($a-zA-Z0-9\-]+\.)+))($a-zA-Z]{2,4}|$0-9]{1,3})(\]?)$ '; var $pattern_ip='($0-9]{1,3}\.$0-9]{1,3}\.$0-9]{1,3}\.$0-9]{1,3})'; var $pattern_url='^(http|ftp)://(www\.)?.+\.(com|net|org)$'; /** * The constructor of the validation class * @param string $string the string which have to be validated * @desc The constructor of the validation class */ function validate($string){ $this->string=$string; } /** * Validates the string if it consists of alphabetical chars * @param int $num_chars the number of chars in the string * @param string $behave defines how to check the string: min, max or exactly number of chars * @desc Validates the string if it consists of alphabetical chars */ function alpha($num_chars,$behave){ if($behave=="min"){ $pattern="^$a-zA-Z]{".$num_chars.",}$"; }else if ($behave=="max"){ $pattern="^$a-zA-Z]{0,".$num_chars."}$"; }else if ($behave=="exactly"){ $pattern="^$a-zA-Z]{".$num_chars.",".$num_chars."}$"; } return ereg($pattern,$this->string); } /** * Validates the string if it consists of lowercase alphabetical chars * @param int $num_chars the number of chars in the string * @param string $behave defines how to check the string: min, max or exactly number of chars * @desc Validates the string if it consists of lowercase alphabetical chars */ function alpha_lowercase($num_chars,$behave){ if($behave=="min"){ $pattern="^$a-z]{".$num_chars.",}$"; }else if ($behave=="max"){ $pattern="^$a-z]{0,".$num_chars."}$"; }else if ($behave=="exactly"){ $pattern="^$a-z]{".$num_chars.",".$num_chars."}$"; } return ereg($pattern,$this->string); } /** * Validates the string if it consists of uppercase alphabetical chars * @param int $num_chars the number of chars in the string * @param string $behave defines how to check the string: min, max or exactly number of chars * @desc Validates the string if it consists of uppercalse alphabetical chars */ function alpha_uppercase($num_chars,$behave){ if($behave=="min"){ $pattern="^$A-Z]{".$num_chars.",}$"; }else if ($behave=="max"){ $pattern="^$A-Z]{0,".$num_chars."}$"; }else if ($behave=="exactly"){ $pattern="^$A-Z]{".$num_chars.",".$num_chars."}$"; } return ereg($pattern,$this->string); } /** * Validates the string if it consists of numeric chars * @param int $num_chars the number of chars in the string * @param string $behave defines how to check the string: min, max or exactly number of chars * @desc Validates the string if it consists of numeric chars */ function numeric($num_chars,$behave){ if($behave=="min"){ $pattern="^$0-9]{".$num_chars.",}$"; }else if ($behave=="max"){ $pattern="^$0-9]{0,".$num_chars."}$"; }else if ($behave=="exactly"){ $pattern="^$0-9]{".$num_chars.",".$num_chars."}$"; } return ereg($pattern,$this->string); } /** * Validates the string if it consists of alphanumerical chars * @param int $num_chars the number of chars in the string * @param string $behave defines how to check the string: min, max or exactly number of chars * @desc Validates the string if it consists of alphanumerical chars */ function alpha_numeric($num_chars,$behave){ if($behave=="min"){ $pattern="^$0-9a-zA-Z]{".$num_chars.",}$"; }else if ($behave=="max"){ $pattern="^$0-9a-zA-Z]{0,".$num_chars."}$"; }else if ($behave=="exactly"){ $pattern="^$0-9a-zA-Z]{".$num_chars.",".$num_chars."}$"; } return ereg($pattern,$this->string); } /** * Validates the string if its a valid postcode * @param string $country_code the country code for the country of the postcode (de,en) * @desc Validates the string if its a valid postcode */ function postcode($country_code){ if(array_key_exists($country_code,$this->pattern_postcode)){ return ereg($this->pattern_postcode$$country_code],$this->string); }else{ return false; } } /** * Validates the string if its a valid email address * @desc Validates the string if its a valid email adress */ function email(){ return ereg($this->pattern_email,$this->string); } /** * Validates the string if its a valid ip address * @desc Validates the string if its a valid ip address */ function ip_address(){ return ereg($this->pattern_ip,$ip); } /** * Validates the string if its a valid URL * @desc Validates the string if its a valid URL */ function url(){ return ereg($this->pattern_url,$ip); } } ?> |
姓名: | |||
佈告內容: | |||
其他選項: | |||
|