向奕鸣:专注阳宅风水与墓地风水堪舆!

几个函数范例

来源:向奕鸣

$para 来调用session, get, post, cookie 等类的变量,但是这在安全上会造成一定的隐患,也就是说可以通过 get 模式来欺骗系统,所以在 php 4.1.0 以后的版本中,registor_global 的默认值变成了 off ,

几个函数范例

取得系统变量/取得字符串的指定部分,且不会出现将全角字符截断的现象/取得程序的执行时间....... 简 介:习惯早期版本的朋友可能会习惯于直接通过 $para 来调用session, get, post, cookie 等类的变量,但是这在安全上会造成一定的隐患,也就是说可以通过 get 模式来欺骗系统,所以在 php 4.1.0 以后的版本中,registor_global 的默认值变成了 off ,也就是你不许通过系统数组来分类调用相关变量,但这也在一定程度上给习惯了原来模式的用户带来了不便,也使得一些早期的程序必须经过修改才可以在新的环境下运行,本函数基本上可以解决掉以上问题,同时通过分类激活避免用 get 伪装 post 等变量的问题。

效 果:是可以直接通过 $para 来调用相关变量(相当于 registor_global = on),好处是可以分类激活,避免通过 get 伪装 post 等信息!

方 法:模式一:GetPara( get , my_get_para ) 取得名为 my_get_para 的 get 变量值 模式一:GetPara( post ) 声明所有 post 变量为可(像老版本php一样)直接调用的变量 其 他:GetPara( file ) ; GetPara( env ) ; GetPara( server ) 等... */ function GetPara($type = get , $para = ) { //Coded By Windy_sk 20030529 v1.5 $type = _ .strtoupper($type); if(phpversion() 4.1.0 ) { if($type = _FILES ) { $type = HTTP_POST .$type; } elseif($type = _REQUEST ) { return $para?false: } else { $type = HTTP .$type. _VARS } @eval( global \${$type}; } eval( \$flag = isset(\${$type}); if($flag) { eval( \$type = \${$type}; } else { return $para?false: } if($para) { return isset($type[$para])?$type[$para]: } while(list($key, $value) = each($type)) { global $key; $key = $value; } return true; }

/* 函数名:substrPro

作 用:取得字符串的指定部分,且不会出现将全角字符截断的现象

简 介:本函数是 substr 针对全角字符的扩展,避免截断全角字符,同时如果 $mode = true 的话,会将全角字符看作是一个字符!

方 法:substrPro( 一1二三四4五5六七八8九十0 , 2, 6) - 1二三四 substrPro( 一1二三四4五5六七八8九十0 , 2, 6, true) - 1二三四4五 注:暂不支持参数为负值 */ function substrPro($Modi_Str, $start, $length, $mode = false){ //Coded By Windy_sk 20020603 v2.0 $n = 0; for($i=0;$i $start;$i++){ if(ord(substr($Modi_Str,$i,1)) 0xa0){ if($mode){ $start++; $i++; } $n++; } } if(!$mode)$start = $start + $n%2; $The_length = $start+$length; for($i=$start;$i $The_length;$i++){ if(ord(substr($Modi_Str,$i,1)) 0xa0){ $The_Str.=substr($Modi_Str,$i,2); $i++; if($mode) $The_length++; }else{ $The_Str.=substr($Modi_Str,$i,1); } } return $The_Str; }

/* 以下两个函数为取得程序的执行时间,并可定制精确度(最多精确到 1E-10 s) */ function getmicrotime() { if(function_exists( microtime )) { list($usec, $sec) = explode( ,microtime()); return $usec + $sec; } else { return time(); } }

function gettimediff($time_start, $decimal = 3) { $time_end = getmicrotime(); $time = (string)($time_end - $time_start); $time = preg_replace( /^([\d]+.[\d]{ .$decimal. })[\d]*$/ , \\1 ,$time); return $time; }

/* 函数名:ob_handle

作 用:通过ob_start( ob_handle ) 来处理缓存数据,并在 flush 前对其进行加工处理。

方 法:先设置 $ob_function 为函数名列表(以 作间隔,需均为字符串处理函数,且便两个数可为一,可以使自定义变量),再设置 ob_start( ob_handle ) 调用本函数进行缓存控制,最后 ob_end_flush() 输出缓存。(注: $ob_function 在 ob_end_flush() 之前设置均有效!) */ $ob_function = htmlspecialchars;trim function ob_handle ($content) { //Coded By Windy_sk 20030510 v1.0 global $ob_function, $cache_file; $f_list = split( , $ob_function); for($i=0; $i count($f_list); $i++) { $temp = trim($f_list[$i]); if(function_exists($temp)) $content = $temp($content); } if(phpversion() 4.0.6 ) $content = ob_gzhandler($content, 1); return $content; }

/* 函数名:RndKey

作 用:生成规定长度的随机字串

方 法:RndKey(8) - 1d@5cDO( */ function RndKey($lng){ $char_list = array(); $char_list[] = 1234567890 $char_list[] = ABCDEFGHIJKLMNOPQRSTUVWXYZ $char_list[] = abcdefghijklmnopqrstuvwxyz $char_list[] = !@^()_:+\- $char_length = count($char_list); $Rnd_Key = for($i=1; $i =$lng; $i++){ $Rnd_Str = $char_list[rand(1,$char_length) - 1]; $Rnd_Key .= substr($Rnd_Str, rand(0,strlen($Rnd_Str)-1), 1); } return($Rnd_Key); }

/* 函数名:cut_words

作 用:将连续的文本按照全角字符和半角单词拆分 */

function cut_words($str) { //Coded By Windy_sk 20020805 v1.0 $str = str_replace( \r\n , \n ,$str) . preg_match_all( /[\xa0-\xff]?./ , $str, $arr1); $arr1 = $arr1[0]; $arr2 = array(); $n = 0; for($i=0; $i count($arr1); $i++) { if(ord($arr1[$i]) =0xa0) { if(!empty($arr2[$n])) $n++; $arr2[$n++] = $arr1[$i]; } elseif(preg_match( /\s/m , $arr1[$i])) { $arr2[++$n] = $arr1[$i]; } else { $arr2[$n] .= $arr1[$i]; } } return join( , $arr2); } ?

本文由向奕鸣整理发布,转载请注明出自http://www.xjfsg.com/news/37189.shtml

上一篇:出道就是巅峰起点,出道就是巅峰怎么办txt下载下一篇:几个函数范例

相关文章

图文资讯

友情链接: 向奕鸣