$I_len2) return false; return true; } //----------------------------------------------------------------------------------- //----------------------------------------------------------------------------------- // 函数名:CheckUser($C_user) // 作 用:判断是否为合法用户名 // 参 数:$C_user(待检测的用户名) // 返回值:布尔值 // 备 注:无 //----------------------------------------------------------------------------------- function CheckUser($C_user) { if (!CheckLengthBetween($C_user, 4, 20)) return false; //宽度检验 if (!ereg("^[_a-zA-Z0-9]*$", $C_user)) return false; //特殊字符检验 return true; } //----------------------------------------------------------------------------------- //----------------------------------------------------------------------------------- // 函数名:CheckPassword($C_passwd) // 作 用:判断是否为合法用户密码 // 参 数:$C_passwd(待检测的密码) // 返回值:布尔值 // 备 注:无 //----------------------------------------------------------------------------------- function CheckPassword($C_passwd) { if (!CheckLengthBetween($C_passwd, 4, 20)) return false; //宽度检测 if (!ereg("^[_a-zA-Z0-9]*$", $C_passwd)) return false; //特殊字符检测 return true; } //----------------------------------------------------------------------------------- //----------------------------------------------------------------------------------- // 函数名:CheckTelephone($C_telephone) // 作 用:判断是否为合法电话号码 // 参 数:$C_telephone(待检测的电话号码) // 返回值:布尔值 // 备 注:无 //----------------------------------------------------------------------------------- function CheckTelephone($C_telephone) { if (!ereg("^[+]?[0-9]+([xX-][0-9]+)*$", $C_telephone)) return false; return true; } //----------------------------------------------------------------------------------- //----------------------------------------------------------------------------------- // 函数名:CheckValueBetween($N_var, $N_val1, $N_val2) // 作 用:判断是否是某一范围内的合法值 // 参 数:$N_var 待检测的值 // $N_var1 待检测值的上限 // $N_var2 待检测值的下限 // 返回值:布尔值 // 备 注:无 //----------------------------------------------------------------------------------- function CheckValueBetween($N_var, $N_val1, $N_val2) { if ($N_var < $N_var1 || $N_var > $N_var2) { return false; } return true; } //----------------------------------------------------------------------------------- //----------------------------------------------------------------------------------- // 函数名:CheckPost($C_post) // 作 用:判断是否为合法邮编(固定长度) // 参 数:$C_post(待check的邮政编码) // 返回值:布尔值 // 备 注:无 //----------------------------------------------------------------------------------- function CheckPost($C_post) { $C_post=trim($C_post); if (strlen($C_post) == 6) { if(is_int($C_post)) { return true; } else { return false; } } else { return false; } } //----------------------------------------------------------------------------------- //----------------------------------------------------------------------------------- // 函数名:CheckExtendName($C_filename,$A_extend) // 作 用:上传文件的扩展名判断 // 参 数:$C_filename 上传的文件名 // $A_extend 要求的扩展名 // 返回值:布尔值 // 备 注:无 //----------------------------------------------------------------------------------- function CheckExtendName($C_filename,$A_extend) { if(strlen(trim($C_filename)) < 5) { return 0; //返回0表示没上传图片 } $lastdot = strrpos($C_filename, "."); //取出.最后出现的位置 $extended = substr($C_filename, $lastdot+1); //取出扩展名 for($i=0;$i1) { for($j=0;$j$LimitSize[0] || $size[1]>$LimitSize[1]) { AlertExit('图片尺寸过大'); return false; } return true; } //----------------------------------------------------------------------------------- //----------------------------------------------------------------------------------- // 函数名:Alert($C_alert) // 作 用:非法操作警告 // 参 数:$C_alert(提示的错误信息) // window.close()(关闭该窗口) // 返回值:字符串 // 备 注:无 //----------------------------------------------------------------------------------- function Alertandclose($C_alert) { echo ""; } //----------------------------------------------------------------------------------- //----------------------------------------------------------------------------------- // 函数名:AlertExit($C_alert,$I_goback=0) // 作 用:非法操作警告 // 参 数:$C_alert(提示的错误信息) // $I_goback(返回到那一页) // 返回值:字符串 // 备 注:无 //----------------------------------------------------------------------------------- function AlertExit($C_alert,$I_goback=0) { if($I_goback<>0) { echo ""; exit; } else { echo ""; exit; } } //----------------------------------------------------------------------------------- //----------------------------------------------------------------------------------- // 函数名:goUrlAndAlert($C_alert,$url) // 作 用:非法操作警告并转向特定网址 // 参 数:$C_alert(提示的错误信息) // 返回值:字符串 // 备 注:无 //----------------------------------------------------------------------------------- function goUrlAndAlert($C_alert,$url) { if($url > "") { echo ""; exit; } else { echo ""; exit; } } //----------------------------------------------------------------------------------- // 函数名:goUrl($url) // 作 用:转到指定网址 // 返回值:字符串 // 备 注:无 //----------------------------------------------------------------------------------- function goUrl($url) { if($url > "") { echo ""; exit; } else { echo ""; exit; } } function AlertAndBack($C_alert) { echo ""; exit; } //----------------------------------------------------------------------------------- // 函数名:ReplaceSpacialChar($C_char) // 作 用:特殊字符替换函数 // 参 数:$C_char(待替换的字符串) // 返回值:字符串 // 备 注:无 //----------------------------------------------------------------------------------- function ReplaceSpecialChar($C_char) { $C_char=HTMLSpecialChars($C_char); //将特殊字元转成 HTML 格式。 $C_char=nl2br($C_char); //将回车替换为
$C_char=str_replace(" "," ",$C_char); //替换空格替换为 $C_char=str_replace(" $char='¥5,645,132.31' //----------------------------------------------------------------------------------- function ExchangeMoney($N_money) { $A_tmp=explode(".",$N_money ); //将数字按小数点分成两部分,并存入数组$A_tmp $I_len=strlen($A_tmp[0]); //测出小数点前面位数的宽度 if($I_len%3==0) { $I_step=$I_len/3; //如前面位数的宽度mod 3 = 0 ,可按,分成$I_step部分 }else { $step=($len-$len%3)/3+1; //如前面位数的宽度mod 3 != 0 ,可按,分成$I_step部分+1 } $C_cur=""; //对小数点以前的金额数字进行转换 while($I_len<>0) { $I_step--; if($I_step==0) { $C_cur .= substr($A_tmp[0],0,$I_len-($I_step)*3); }else { $C_cur .= substr($A_tmp[0],0,$I_len-($I_step)*3).","; } $A_tmp[0]=substr($A_tmp[0],$I_len-($I_step)*3); $I_len=strlen($A_tmp[0]); } //对小数点后面的金额的进行转换 if($A_tmp[1]=="") { $C_cur .= ".00"; }else { $I_len=strlen($A_tmp[1]); if($I_len<2) { $C_cur .= ".".$A_tmp[1]."0"; }else { $C_cur .= ".".substr($A_tmp[1],0,2); } } //加上人民币符号并传出 $C_cur="¥".$C_cur; return $C_cur; } //----------------------------------------------------------------------------------- //接收变理方式 function request1($par,$Method) { if (isset($_GET["$par"]) || isset($_POST["$par"])) { if ($Method=='get') { $thisValue=$_GET["$par"]; } else { $thisValue=$_POST["$par"]; } } else { return ""; } } //----------------------------------------------------------------------------------- // 函数名:request($par,$dot,$Method) // 作 用:表单checkbox传值 // 参 数:$par(表单域名称),$dot(分隔符),$Method(提交的方法) // 返回值:字符串 // 备 注:本函数示例:request($par,",","get") //----------------------------------------------------------------------------------- function request($par,$dot,$Method) { if (isset($_GET["$par"]) || isset($_POST["$par"])) { if ($Method=='get') { $thisValue=$_GET["$par"]; } else { $thisValue=$_POST["$par"]; } foreach($thisValue as $i=>$a) { $loveString.=$a."$dot"; } //substr($str,0,$n)//取$str左邊$n個字 //substr($str,strlen($str)-$n)//取$str右邊$n個字符 $loveString=substr($loveString,0,strlen($loveString)-1); return $loveString; } else { return ""; } } //----------------------------------------------------------------------------------- // 函数名:setEdit($e_form_name = 'my_text_area',$e_form_value = '',$e_toolbar = 'AdminMode',$height='',$width = 590) // 作 用:web编辑器 //----------------------------------------------------------------------------------- function setEditor($e_form_name = 'my_text_area',$e_form_value = '',$e_toolbar = 'AdminMode',$height='',$width = 590) { global $root_dir,$sys_dir; $e_path = $sys_dir."editor/FCKeditor/"; include($e_path."fckeditor.php"); $obj = new FCKeditor($e_form_name); $obj -> BasePath = $root_dir."editor/FCKeditor/"; $obj -> ToolbarSet = $e_toolbar; $obj -> Width = $width; $height?$obj -> Height = $height:$obj -> Height = 400; if (get_magic_quotes_gpc()) { $v = stripslashes($e_form_value); } else { $v = $e_form_value; } $obj -> Value = $v; return $obj -> CreateHtml(); } //----------------------------------------------------------------------------------- // 函数名:getRealIp() // 作 用:获取真实IP //----------------------------------------------------------------------------------- function getRealIp() { $ip=false; if(!empty($_SERVER["HTTP_CLIENT_IP"])) { $ip = $_SERVER["HTTP_CLIENT_IP"]; } if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ips = explode (", ", $_SERVER['HTTP_X_FORWARDED_FOR']); if ($ip) { array_unshift($ips, $ip); $ip = FALSE; } for ($i = 0; $i < count($ips); $i++) { if (!eregi ("^(10|172\.16|192\.168)\.", $ips[$i])) { $ip = $ips[$i]; break; } } } return ($ip ? $ip : $_SERVER['REMOTE_ADDR']); } //----------------------------------------------------------------------------------- // 函数名:getOS() // 作 用:获得客户端的操作系统 //----------------------------------------------------------------------------------- function getOS() { if (!isset($_SERVER['HTTP_USER_AGENT'])) { return 'Unknown'; } $agent = $_SERVER['HTTP_USER_AGENT']; $os = ''; if (eregi('win', $agent) && eregi('nt 5.1', $agent)) { $os = 'Windows XP'; } elseif (eregi('win 9x', $agent) && strpos($agent, '4.90')) { $os = 'Windows ME'; } elseif (eregi('win', $agent) && ereg('98', $agent)) { $os = 'Windows 98'; } elseif (eregi('win', $agent) && strpos($agent, '95')) { $os = 'Windows 95'; } elseif (eregi('win', $agent) && eregi('nt 5', $agent)) { $os = 'Windows 2000'; } elseif (eregi('win', $agent) && eregi('nt', $agent)) { $os = 'Windows NT'; } elseif (eregi('win', $agent) && ereg('32', $agent)) { $os = 'Windows 32'; } elseif (eregi('linux', $agent)) { $os = 'Linux'; } elseif (eregi('unix', $agent)) { $os = 'Unix'; } elseif (eregi('sun', $agent) && eregi('os', $agent)) { $os = 'SunOS'; } elseif (eregi('ibm', $agent) && eregi('os', $agent)) { $os = 'IBM OS/2'; } elseif (eregi('Mac', $agent) && eregi('PC', $agent)) { $os = 'Macintosh'; } elseif (eregi('PowerPC', $agent)) { $os = 'PowerPC'; } elseif (eregi('AIX', $agent)) { $os = 'AIX'; } elseif (eregi('HPUX', $agent)) { $os = 'HPUX'; } elseif (eregi('NetBSD', $agent)) { $os = 'NetBSD'; } elseif (eregi('BSD', $agent)) { $os = 'BSD'; } elseif (ereg('OSF1', $agent)) { $os = 'OSF1'; } elseif (ereg('IRIX', $agent)) { $os = 'IRIX'; } elseif (eregi('FreeBSD', $agent)) { $os = 'FreeBSD'; } elseif (eregi('teleport', $agent)) { $os = 'teleport'; } elseif (eregi('flashget', $agent)) { $os = 'flashget'; } elseif (eregi('webzip', $agent)) { $os = 'webzip'; } elseif (eregi('offline', $agent)) { $os = 'offline'; } else { $os = 'Unknown'; } return $os; } function random($length, $numeric = 0) { PHP_VERSION < '4.2.0' && mt_srand((double)microtime() * 1000000); if($numeric) { $hash = sprintf('%0'.$length.'d', mt_rand(0, pow(10, $length) - 1)); } else { $hash = ''; $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz'; $max = strlen($chars) - 1; for($i = 0; $i < $length; $i++) { $hash .= $chars[mt_rand(0, $max)]; } } return $hash; } //将ip转化为长整型字符串 function ipToLong($ip) { return sprintf("%u",ip2long($ip)); } //获得一个guid function mgGetGuid() { return md5(uniqid(time())); } /* * 中文截取,支持gb2312,gbk,utf-8,big5 * * @param string $str 要截取的字串 * @param int $start 截取起始位置 * @param int $length 截取长度 * @param string $charset utf-8|gb2312|gbk|big5 编码 * @param $suffix 是否加尾缀 */ function csubstr($str, $start=0, $length, $charset="utf-8", $suffix=true) { if(function_exists("mb_substr")) return mb_substr($str, $start, $length, $charset); $re['utf-8'] = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/"; $re['gb2312'] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/"; $re['gbk'] = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/"; $re['big5'] = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/"; preg_match_all($re[$charset], $str, $match); $slice = join("",array_slice($match[0], $start, $length)); if($suffix) return $slice."…"; return $slice; } /** * 根据字节数转换成相应的单位 * * @param int $byte 字节数字 * @return 转换后单位的字符串(如1.34K,2.30M) */ function sizeCount($byte) { if($byte >= 1073741824) { $byte = round($byte / 1073741824, 2) . " G"; } elseif($byte >= 1048576) { $byte = round($byte / 1048576, 2) . " M"; } elseif($byte >= 1024) { $byte = round($byte / 1024, 2) . " K"; } else { $byte = $byte . " bytes"; } return $byte; } function delHtmlCode($vStr) { for($i=0;$i]*>.*?<\/a>/is"; $Filter[3] = "/<[a-z]+\s*(?:onerror|onload|onunload|onresize|onblur|onchange|onclick|ondblclick|onfocus|onkeydown|onkeypress|onkeyup|onmousemove|onmousedown|onmouseout|onmouseover|onmouseup|onselect)[^>]*>/is"; $String=nl2br($String); $String=str_replace("

",CHR(10) & CHR(10),$String); $String=str_replace("

","",$String); $String=str_replace(" ",CHR(9),$String); $String=str_replace(" ",CHR(32),$String); $String=str_replace("
","",$String); $String=str_replace("","",$String); $String=str_replace("","",$String); $String=str_replace(""",CHR(34),$String); return preg_replace($Filter,"",$String); } //保存格式 function getHtml($thiscontent) { $thiscontent = str_replace(">", ">",$thiscontent); $thiscontent = str_replace("<", "<",$thiscontent); $thiscontent = str_replace(CHR(32), " ",$thiscontent); $thiscontent = str_replace(CHR(9), " ",$thiscontent); $thiscontent = str_replace(CHR(34), """,$thiscontent); $thiscontent = str_replace(CHR(39), "'",$thiscontent); $thiscontent = str_replace(CHR(13), "",$thiscontent); $thiscontent = str_replace(CHR(10), "
",$thiscontent); return $thiscontent; } //显示格式 function get_Html($thiscontent) { if(!empty($thiscontent)) { $thiscontent = str_replace(">",">",$thiscontent); $thiscontent = str_replace("<","<",$thiscontent); $thiscontent = str_replace(" ",CHR(32),$thiscontent); $thiscontent = str_replace(" ",CHR(9),$thiscontent); $thiscontent = str_replace(""",CHR(34),$thiscontent); $thiscontent = str_replace("'",CHR(39), $thiscontent); $thiscontent = str_replace("",CHR(13),$thiscontent); $thiscontent = str_replace("
",CHR(10),$thiscontent); return $thiscontent; } } /* 防注入 */ /* 过滤函数 */ //整型过滤函数 # getParaNum("123344","F",0) function getParaNum($number,$Ntype,$defaultValue) { if (!$number) { $number=$defaultValue; } switch ($Ntype) { case "I": return intval($number); break; case "F": return floatval($number); break; } } //字段型字符串过滤函数 function getParaStr($string,$strLen,$defaultValue) { $string=trim($string); if ($strLen!=0) { $string = substr($string,0,$strLen); } if ($string=="") { $string = $defaultValue; } if (!get_magic_quotes_gpc()) { return addslashes($string); } return $string; } //备注型字符串过滤函数 function getParaContent($string,$strLen,$defaultValue) { if ($strLen!=0) { $string = substr($string,0,$strLen); } if ($string=="") { $string = $defaultValue; } if (!get_magic_quotes_gpc()) { return addslashes($string); } return $string; } //检查字符串是否为空 function chkIsEmpty($string) { if (!is_string($string)) return true; if (empty($string)) return true; if ($string == '') return true; return false; } //计算出给出的日期是星期几 function GetWeekDay($date) { $dateArr = explode("-", $date); return date("w", mktime(0,0,0,$dateArr[1],$dateArr[2],$dateArr[0])); } //计算时间加 function DateAdd ($interval, $number, $date) { $now=strtotime($date); $m=$number*24*60*60; $diff=$now+$m; $oldday=date("Y-m-d",$diff); return $oldday; } //计算时间差 Function DateDiff($interval,$date1,$date2) { // 得到两日期之间间隔的秒数 $d1=strtotime($date1); $d2=strtotime($date2); $gettim=$d2-$d1; switch ($interval) { case "y": $retval = round(($gettim)/3600/24/365); break; case "m": $retval = round(($gettim)/3600/24/30); break; case "w": $retval = round(($gettim)/3600/24/7); break; case "d": $retval = round(($gettim)/3600/24); break; case "h": $retval = round(($gettim)/3600); break; case "n": $retval = round(($gettim)/60); break; case "s": $retval = round($gettim); break; } return $retval; } function delfile($del_file) { if (file_exists($del_file)) { $new=unlink($del_file); if(!$new) { echo "操作失败:无法删除文件,可能是你没有足够的权限!".$del_file; exit; } } } //截取GB2312中文字符串 function mysubstr($str, $start, $len) { $tmpstr = ""; $strlen = $start + $len; for($i = 0; $i < $strlen; $i++) { if(ord(substr($str, $i, 1)) > 0xa0) { $tmpstr .= substr($str, $i, 2); $i++; } else $tmpstr .= substr($str, $i, 1); } return $tmpstr; } //截取utf8编码的多字节字符串 function utf8Substr($str,$from,$len) { $cutstring=preg_replace('#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$from.'}'.'((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$len.'}).*#s', '$1',$str); $cutstring=str_replace("

","",$cutstring); $cutstring=str_replace("

","",$cutstring); if (strlen($cutstring)>$len) { return $cutstring."..."; } else { return $cutstring; } } /* 中文字符串截取 Utf-8、gb2312都支持的汉字截取函数 cut_str(字符串, 截取长度, 开始长度, 编码); 编码默认为 utf-8 开始长度默认为 0 */ function cut_str($string, $sublen, $start = 0, $code = 'UTF-8') { if($code == 'UTF-8') { $pa = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/"; preg_match_all($pa, $string, $t_string); if(count($t_string[0]) - $start > $sublen) return join('', array_slice($t_string[0], $start, $sublen))."..."; return join('', array_slice($t_string[0], $start, $sublen)); } else { $start = $start*2; $sublen = $sublen*2; $strlen = strlen($string); $tmpstr = ''; for($i=0; $i< $strlen; $i++) { if($i>=$start && $i< ($start+$sublen)) { if(ord(substr($string, $i, 1))>129) { $tmpstr.= substr($string, $i, 2); } else { $tmpstr.= substr($string, $i, 1); } } if(ord(substr($string, $i, 1))>129) $i++; } if(strlen($tmpstr)< $strlen ) $tmpstr.= "..."; return $tmpstr; } } //编码转换函数 function codeChange($str,$method) { if ($method==0) { return iconv('GB2312','UTF-8',$str);//gb213转utf-8 } elseif ($method==1) { return iconv('UTF-8','GB2312',$str); } else { return $str; } } #中英文字符串截取 function cutstring($sourcestr,$cutlength,$showstr) { $sourcestr=strip_tags($sourcestr); if($sourcestr==NULL||$sourcestr=="") return ""; if (strlen($sourcestr) <= $cutlength) return $sourcestr; $sourcestr=str_replace(">",">",$sourcestr); $sourcestr=str_replace("<","<",$sourcestr); $sourcestr=str_replace(" ",chr(32),$sourcestr); $sourcestr=str_replace(""",chr(34),$sourcestr); $sourcestr=str_replace("'",chr(39),$sourcestr); $sourcestr=str_replace("",chr(13),$sourcestr); $sourcestr=str_replace("
",chr(10),$sourcestr); $sourcestr=str_replace("
",chr(10),$sourcestr); $returnstr=''; $i=0; $n=0; $str_length=strlen($sourcestr);//字符串的字节数 while (($n<$cutlength) and ($i<=$str_length)) { $temp_str=substr($sourcestr,$i,1); $ascnum=Ord($temp_str);//得到字符串中第$i位字符的ascii码 if ($ascnum>=224) //如果ASCII位高与224, { $returnstr=$returnstr.substr($sourcestr,$i,3); //根据UTF-8编码规范,将3个连续的字符计为单个字符 $i=$i+3; //实际Byte计为3 $n++; //字串长度计1 } elseif ($ascnum>=192) //如果ASCII位高与192, { $returnstr=$returnstr.substr($sourcestr,$i,2); //根据UTF-8编码规范,将2个连续的字符计为单个字符 $i=$i+2; //实际Byte计为2 $n++; //字串长度计1 } elseif ($ascnum>=65 && $ascnum<=90) //如果是大写字母, { $returnstr=$returnstr.substr($sourcestr,$i,1); $i=$i+1; //实际的Byte数仍计1个 $n++; //但考虑整体美观,大写字母计成一个高位字符 } else //其他情况下,包括小写字母和半角标点符号, { $returnstr=$returnstr.substr($sourcestr,$i,1); $i=$i+1; //实际的Byte数计1个 $n=$n+0.5; //小写字母和半角标点等与半个高位字符宽... } } if ($str_length>$cutlength){ $returnstr = $returnstr .$showstr;//超过长度时在尾处加上省略号 } return $returnstr; } //截取英文单词 function subwords($words,$num) { //从 $words 字符串中 截取前 $num 个单词 // functioned by PHP designer Hiosiao, $total_num = str_word_count($words); // 获取$words 中单词个数 if($total_num <= $num) { // 如果$words 中单词个数少于 $num return $words; } else { $pattern = '/([\S]+?[ ]+){'.$num.'}/'; preg_match($pattern, $words, $out); return $out[0].'...'; //如果字符串过长,将以 ... 结束 } } #价格千位割分,保留小数点 function priceformat($price) { if ($price) { if(is_numeric($price)) { $priceformat=number_format($price,0); } else { $priceformat=0; } } else { $priceformat="请致电"; } return $priceformat; } //生是缩略图类 /* * 图片大小比例调整 * * @param $filename 图片路径 * @param $w  目标宽度 * @param $h   目标高度 * @param $override 是否覆盖原文件 * @param $background 是否产生背景, 如果要求产生背景则产生图像是指定的大小, 图片内容居中 * @param $color 背影色 * @param $tofile 新产生的文件名 * @param $tojpg 是否让缩略图只生成JPG格式 */ function RatioAdjuct($filename, $w=150, $h=180, $background, $color,$tofile,$tojpg=1) { list ($imgWidth, $imgHeight) = getImageSize($filename); $ratioX = $imgWidth / $w; $ratioY = $imgHeight / $h; if ($ratioX > $ratioY || $ratioX == $ratioY){ $dst_w = $w; $dst_h = ceil($imgHeight / $ratioX); } else if ($ratioY > $ratioX){ $dst_h = $h; $dst_w = ceil($imgWidth / $ratioY); } //判断图片类型 switch (strtolower(strrchr($filename, '.'))){ case '.jpg' : case '.jpeg' : $im = imageCreateFromJpeg($filename); break; case '.gif' : $im = imageCreateFromGif($filename); break; case '.png' : $im = imageCreateFromPng($filename); } //是否有背景色 if (null !== $background) { //将背景色转换为十进制的红绿蓝值 $dec = hexdec($color); $red = 0xFF & ($dec >> 0x10); $green = 0xFF & ($dec >> 0x8); $blue = 0xFF & $dec; //居中定位并复制 $dst_pos = array ('d_x' => 0, 'd_y' => 0); ($dst_w == $w) ? ( $dst_pos['d_y'] = (($h - $dst_h) / 2) ) : ($dst_pos['d_x'] = (($w - $dst_w) / 2)); $imBox = imageCreateTrueColor($w, $h); $color_bg = imageColorAllocate($imBox, $red, $green, $blue); imageFill($imBox, 0, 0, $color_bg); imagecopyresampled($imBox, $im, $dst_pos['d_x'], $dst_pos['d_y'], 0, 0, $dst_w, $dst_h, $imgWidth, $imgHeight); }else{ $imBox = imageCreateTrueColor($dst_w, $dst_h); imagecopyresampled($imBox, $im, 0, 0, 0, 0, $dst_w, $dst_h, $imgWidth, $imgHeight); } //不替换源图片 /* if (null === $override) $filename = str_replace(strrchr($filename, '.'), '', $filename) . '_thumb.png'; return imagejpeg($imBox, $filename) ? $filename : false; */ if(empty($tofile)) { $tofile = str_replace(strrchr($filename, '.'), '', $filename) . '_small.jpg'; } if($tojpg=='') { switch (strtolower(strrchr($filename, '.'))){ case '.jpg' : case '.jpeg' : imagejpeg($imBox,$tofile,100); break; case '.gif' : imagegif($imBox,$tofile); break; case '.png' : imagepng($imBox,$tofile); } }else{ imagejpeg($imBox,$tofile,100); } imagedestroy($imBox); imagedestroy($im); return $tofile; } ?>
  • ·
  • "; $nclass_qry=mysql_query($sql_nclass); $nclass_row=mysql_fetch_row($nclass_qry); if ($nclass_row[0]) { return $nclass_row[0]; } else { return "/images/nopic.gif"; } } #获取图片张数量 function get_piturenum($leixing,$tuxing,$newsid) { if($newsid!=0) { $sql_num=$sql_num." and classid='$newsid'"; } if($leixing) { $sql_num=$sql_num." and sort_type='$leixing'"; } if($tuxing) { $sql_num=$sql_num." and tuxing='$tuxing'"; } $sql_nclass="select count(id) as id from hn_photo_manage where 1=1".$sql_num; $nclass_qry=mysql_query($sql_nclass); $nclass_row=mysql_fetch_array($nclass_qry); if($nclass_row['id']) { return $nclass_row['id']; } else { return 0; } } #获取活动详情 function get_newsinfo($newsid) { global $newsid_classid,$leixing,$title,$title_color,$title_bold,$chandi,$sale_price,$yuan_price,$guige,$guige_gw,$danwei,$zhiliang,$feiliao,$baozhi,$news_image,$news_image1,$view_lx,$geshi,$laiyuan,$content,$liulancount,$writer,$shenhe,$orderid,$addtime; //获取浏览量 $sql="select liulancount from tq_news where newsid='$newsid'"; $rs=mysql_fetch_array(mysql_query($sql)); $liulan=$rs['liulancount']+1; $sql="update tq_news set liulancount='$liulan' where newsid='$newsid'"; mysql_query($sql); $sql_news="select newsid_classid,leixing,title,title_color,title_bold,chandi,sale_price,yuan_price,guige,danwei,zhiliang,feiliao,baozhi,news_image,news_image1,view_lx,geshi,laiyuan,content,liulancount,writer,shenhe, orderid,addtime from tq_news where newsid='$newsid'"; $qry=mysql_query($sql_news); //执行查询语言 $row=mysql_fetch_array($qry); $newsid_classid=$row['newsid_classid']; $leixing=$row['leixing']; $title=$row['title']; $title_color=$row['title_color']; $title_bold=$row['title_bold']; $chandi=$row['chandi']; $sale_price=$row['sale_price']; $yuan_price=$row['yuan_price']; $guige=$row['guige']; $danwei=$row['danwei']; $zhiliang=$row['zhiliang']; $feiliao=$row['feiliao']; $baozhi=$row['baozhi']; $news_image=$row['news_image']; $news_image1=$row['news_image1']; $view_lx=$row['view_lx']; $geshi=$row['geshi']; $laiyuan=$row['laiyuan']; $content=$row['content']; $liulancount=$row['liulancount']; //$fax=$row['fax']; $writer=$row['writer']; $shenhe=$row['shenhe']; $orderid=$row['shenhe']; $addtime=date("Y-m-d",strtotime($row['addtime'])); if($danwei=="g") { $guige_gw=$guige/1000; } else { $guige_gw="$guige"; } switch ($title_bold) { case "b":$a="font-weight:bold"; break; case "i":$a="font-style:italic"; break; case "u":$a="text-decoration:underline"; break; case "bi":$a="font-weight:bold;font-style:italic"; break; } } #获取会员资料信息 function get_memberinfo($username) { if($username) { global $realname,$company,$usertel,$useremail,$lianxifangshi,$logins,$regip,$addtime; $sql_shop="select realname,company,usertel,useremail,lianxifangshi,logins,regip,addtime from member where username='$username'"; $qry=mysql_query($sql_shop); //执行查询语言 $row=mysql_fetch_array($qry); $realname=$row['realname']; $company=$row['company']; $usertel=$row['usertel']; $useremail=$row['useremail']; $lianxifangshi=$row['lianxifangshi']; $logins=$row['logins']; $regip=$row['regip']; $addtime=$row['addtime']; } } #更新会员资料信息 function get_update_memberinfo($company,$realname,$usertel,$useremail,$username) { if($username) { $sql="update member set company='$company',realname='$realname',usertel='$usertel',useremail='$useremail' where username='$username'"; mysql_query($sql); } } #梁才 根据会员名称获取会员ID function get_memberID($username) { global $dblink; //全局变量 if($username) { $sql_nclass="select userid from member where username='$username'"; $nclass_qry=mysql_query($sql_nclass); $nclass_row=mysql_fetch_array($nclass_qry); return $nclass_row['userid']; } } #梁才 根据信息ID获取信息标题 function get_titlename($newsid) { global $dblink; //全局变量 if($newsid!=0) { $sql_nclass="select title from tq_news where newsid=$newsid"; $nclass_qry=mysql_query($sql_nclass); $nclass_row=mysql_fetch_array($nclass_qry); return $nclass_row['title']; } } #梁才 根据信息ID获取字段名称 function get_ziduan_name($ziduan,$newsid) { global $dblink; //全局变量 if($newsid!=0) { $sql_nclass="select $ziduan from tq_news where newsid=$newsid"; $nclass_qry=mysql_query($sql_nclass); $nclass_row=mysql_fetch_array($nclass_qry); return $nclass_row[0]; } } #购物车产品列表 function get_product_name($newsid) { global $dblink; //全局变量 if($newsid!=0) { $sql_nclass="select title from tq_news where newsid in($newsid)"; $qry=mysql_query($sql_nclass); $title=""; while ($row=mysql_fetch_array($qry)) { $title=$title.$row['title'].","; } $title=csubstr($title,$start=0,-1,$charset="utf-8", $suffix=true); return $title; } } #梁才 根据信息ID获取信息内容 function get_titlecontent($newsid) { global $dblink; //全局变量 if($newsid!=0) { $sql_nclass="select content from tq_news where newsid=$newsid"; $nclass_qry=mysql_query($sql_nclass); $nclass_row=mysql_fetch_array($nclass_qry); return $nclass_row['content']; } } #获取二级栏目下拉菜单 function get_lanmuname_bynewsid_max($sort_type,$sartid) { global $newsid_max; //全局变量 $province_select="select newsid_max,max_name,orderid from tq_news_max where sort_type='$sort_type' order by orderid desc"; $qry=mysql_query($province_select); while ($row=mysql_fetch_array($qry)) { if($row['newsid_max']=="$sartid") { $a="style='color:red;'"; } ?> >
  • 暂无数据
  • 暂无消息
  • ·