您好,欢迎访问一九零五行业门户网

我常用的common function库

有零填充、截取中文、halt、html跳转、js跳转、过滤html、检查邮箱合法、转换文字中的超链接为可点击连接、返回时间格式等等常用php函数库。
$v) { $data = str_replace($v, '' . $v . '', $data); } return $data; } else { return str_replace($keywords, '' . $keywords . '', $data); }}/** * 创建完全随机的颜色 * @return string */function makecolor() { $key = '#'; for ($i = 0; $i $key.= rand(0, 9);//生成php随机数 return $key;}/** * 自动加载模型和第三方功能类 * @param string $classname */function autoload($classname) { if (strstr($_server['request_uri'], /operator/) == false) { //服务器不支持script_url if (file_exists(siteroot . '/client/model/' . $classname . '.php')) { require_once siteroot . '/client/model/' . $classname . '.php'; return; } } else { if (file_exists(siteroot . '/manager/model/' . $classname . '.php')) { require_once siteroot . '/manager/model/' . $classname . '.php'; return; } } if (file_exists(siteroot . '/public/modules/' . $classname . '.php')) { require_once siteroot . '/public/modules/' . $classname . '.php'; return; } if (file_exists(siteroot . '/client/order/model/' . $classname . '.php')) { require_once siteroot . '/client/order/model/' . $classname . '.php'; return; }}/** * 用javascript弹出一条信息 * @param $message */function message($message='') { echo('');}/** * 模拟strstr()的第三个参数,返回$h中,$n之前的数据 * //$h = haystack, $n = needle * @param $h * @param $n * @return */function strstrb($h, $n) { return array_shift(explode($n, $h, 2));}/** * 显示错误信息,并跳转至$pageurl,含有样式 * * @param string $messages * @param string $pageurl * @param int $msc 秒数 */function msg($messages, $pageurl='javascript:history.back();', $msc=5) { echo 'system message web system message
', $messages, ' >>>请点此处返回
'; exit();}/** * 检查后面的日期是否大于前面的日期 * @param type $datecome 前面的日期 * @param type $datego 后面的日期 * @return type */function sub_date($datecome, $datego) { $d1 = strtotime($datecome); $d2 = strtotime($datego); $days = round(($d2 - $d1) / 3600 / 24); $days = $days return $days;}/** * 将$string的$length后边的内容用$dot替换 * @param string $string * @param int $length * @param string $dot * @return string */function cutstr($string, $length, $dot = '...') { @extract($string); if (strlen($string) return $string; } $string = htmlspecialchars($string); $string = str_replace(array('&', '', '<', '>'), array('&', '', ''), $string); $strcut = ''; $n = $tn = $noc = 0; while ($n $t = ord($string[$n]); if ($t == 9 || $t == 10 || (32 $tn = 1; $n++; $noc++; } elseif (194 $tn = 2; $n += 2; $noc += 2; } elseif (224 $tn = 3; $n += 3; $noc += 2; } elseif (240 $tn = 4; $n += 4; $noc += 2; } elseif (248 $tn = 5; $n += 5; $noc += 2; } elseif ($t == 252 || $t == 253) { $tn = 6; $n += 6; $noc += 2; } else { $n++; } if ($noc >= $length) { break; } } if ($noc > $length) { $n -= $tn; } $strcut = substr($string, 0, $n); $strcut = str_replace(array('&', '', ''), array('&', '', '<', '>'), $strcut); return $strcut . $dot;}/**+---------------------------------------------------------- * 如果 magic_quotes_gpc 为开启状态,则使用此方法使用为特殊符号前增加转移符号+---------------------------------------------------------- * @access public+---------------------------------------------------------- * @param string $value 可以为数组+---------------------------------------------------------- * @return string+---------------------------------------------------------- */function kaddslashes($value) { return $value = is_array($value) ? array_map('kaddslashes', $value) : addslashes($value);}/**+---------------------------------------------------------- * 为特殊符号前去除转移符号+---------------------------------------------------------- * @access public+---------------------------------------------------------- * @param string $value 可以为数组+---------------------------------------------------------- * @return string+---------------------------------------------------------- */function kstripcslashes($value) { return $value = is_array($value) ? array_map('kstripcslashes', $value) : stripcslashes($value);}/** * 将字符串内容html实体化,避免一些非法信息直接执行。如果参数是数组,则递归。 * @param string $value * @return array */function khtmlspecialchars($value) { return is_array($value) ? array_map('khtmlspecialchars', $value) : preg_replace('/&((#(\d{3,5}|x[a-fa-f0-9]{4})|[a-za-z][a-z0-9]{2,5});)/', '&\\1', str_replace(array('&', '', ''), array('&', '', '<', '>'), $value));}/** * 将字符串中的html去除,如果参数是数组,则递归。 * @param string $value * @return array */function striptags($value) { return $value = is_array($value) ? array_map('striptags', $value) : strip_tags($value);}/** * 检查email的合法性 * * @param string $email * @return bool */function check_email($email) { if (preg_match(/([a-z0-9]*[-_\.]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[\.][a-z]{2,3}([\.][a-z]{2})?/i, $email)) { return true; } else { return false; }}/** * 安全电子邮件地址 * * @param string $email * @param string $title * @param $attributes * @return */function safe_mailto($email, $title = '', $attributes = '') { if (is_array($email)) { $tmp = $email; unset($email); extract($tmp); } $title = (string) $title; if ($title == ) { $title = $email; } for ($i = 0; $i $x[] = substr(' $val) { $x[] = ' ' . $key . '='; for ($i = 0; $i $x[] = | . ord(substr($val, $i, 1)); } $x[] = ''; } } else { for ($i = 0; $i $x[] = substr($attributes, $i, 1); } } } $x[] = '>'; $temp = array(); for ($i = 0; $i $ordinal = ord($title[$i]); if ($ordinal $x[] = | . $ordinal; } else { if (count($temp) == 0) { $count = ($ordinal } $temp[] = $ordinal; if (count($temp) == $count) { $number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64); $x[] = | . $number; $count = 1; $temp = array(); } } } $x[] = ' $x[] = '/'; $x[] = 'a'; $x[] = '>'; $x = array_reverse($x); ob_start(); ?> 0) { switch ($fieldtype) { case 'date' : $date = date('y-m-d', $timestamp); break; case 'time' : $date = date('h:i:s', $timestamp); break; case 'year' : $date = date('y', $timestamp); break; default : $date = date('y-m-d h:i:s', $timestamp); break; } } return $date;}/** * 适应多维数组的递归,并将其中重复的值去掉后返回 * @param array $array * @return array */function super_unique($array) { $result = array_map(unserialize, array_unique(array_map(serialize, $array))); foreach ($result as $key => $value) { if (is_array($value)) { $result[$key] = super_unique($value); } } return $result;}/** * 如果数值不满足2位,自动补零 * @param int $num * @return int */function fullzero($num){ if(strlen($num)!=2){ return '0'.$num; }else{ return $num; }}//返回上一个urlfunction get_visit_url(){ return $_server['http_referer'];}?>
复制代码
其它类似信息

推荐信息