<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://www.jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://www.jackxiang.com/post//</link>
<title><![CDATA[PHP常用函数集合]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Thu, 07 Oct 2010 12:02:06 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	<br/><div class="code">&lt;?php<br/>/*<br/>函数名：GetPara<br/><br/>作 用：取得系统变量<br/><br/>简 介：习惯早期版本的朋友可能会习惯于直接通过 $para 来调用session, get, post, cookie 等类的变量，但是这在安全上会造成一定的隐患，也就是说可以通过 get 模式来欺骗系统，所以在 php 4.1.0 以后的版本中，registor_global 的默认值变成了 off ，也就是你不许通过系统数组来分类调用相关变量，但这也在一定程度上给习惯了原来模式的用户带来了不便，也使得一些早期的程序必须经过修改才可以在新的环境下运行，本函数基本上可以解决掉以上问题，同时通过分类激活避免用 get 伪装 post 等变量的问题。<br/><br/>效 果：是可以直接通过 $para 来调用相关变量（相当于 registor_global = on），好处是可以分类激活，避免通过 get 伪装 post 等信息！<br/><br/>方 法：模式一：GetPara(&quot;get&quot;,&quot;my_get_para&quot;) 取得名为 my_get_para 的 get 变量值<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;模式一：GetPara(&quot;post&quot;) 声明所有 post 变量为可（像老版本php一样）直接调用的变量<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;其 他：GetPara(&quot;file&quot;) ; GetPara(&quot;env&quot;) ; GetPara(&quot;server&quot;) 等...<br/>*/<br/>function GetPara($type = &quot;get&quot;, $para = &quot;&quot;) &#123;<br/> //Coded By Windy_sk 20030529 v1.5<br/><br/> $type = &quot;_&quot;.strtoupper($type);<br/> if(phpversion() &lt; &quot;4.1.0&quot;) &#123;<br/>&nbsp;&nbsp;if($type = &quot;_FILES&quot;) &#123;<br/>&nbsp;&nbsp; $type = &quot;HTTP_POST&quot;.$type;<br/>&nbsp;&nbsp;&#125; elseif($type = &quot;_REQUEST&quot;) &#123;<br/>&nbsp;&nbsp; return $para?false:&quot;&quot;;<br/>&nbsp;&nbsp;&#125; else &#123;<br/>&nbsp;&nbsp; $type = &quot;HTTP&quot;.$type.&quot;_VARS&quot;;<br/>&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;@eval(&quot;global &#92;$&#123;$type&#125;;&quot;);<br/> &#125;<br/> eval(&quot;&#92;$flag = isset(&#92;$&#123;$type&#125;);&quot;);<br/> if($flag) &#123;<br/>&nbsp;&nbsp;eval(&quot;&#92;$type = &#92;$&#123;$type&#125;;&quot;);<br/> &#125; else &#123;<br/>&nbsp;&nbsp;return $para?false:&quot;&quot;;<br/> &#125;<br/> if($para) &#123;<br/>&nbsp;&nbsp;return isset($type&#91;$para&#93;)?$type&#91;$para&#93;:&quot;&quot;;<br/> &#125;<br/> while(list($key, $value) = each($type)) &#123;<br/>&nbsp;&nbsp;global $$key;<br/>&nbsp;&nbsp;$$key = $value;<br/> &#125;<br/> return true;<br/>&#125;<br/><br/><br/>/*<br/>函数名：substrPro<br/><br/>作 用：取得字符串的指定部分，且不会出现将全角字符截断的现象<br/><br/>简 介：本函数是 substr 针对全角字符的扩展，避免截断全角字符，同时如果 $mode = true 的话，会将全角字符看作是一个字符！<br/><br/>方 法：substrPro(&quot;一1二三四4五5六七八8九十0&quot;, 2, 6) -&gt; &quot;1二三四&quot; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;substrPro(&quot;一1二三四4五5六七八8九十0&quot;, 2, 6, true) -&gt; &quot;1二三四4五&quot; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注：暂不支持参数为负值<br/>*/<br/>function substrPro($Modi_Str, $start, $length, $mode = false)&#123; <br/> //Coded By Windy_sk 20020603 v2.0<br/><br/> $n = 0;<br/> for($i=0;$i&lt;$start;$i++)&#123; <br/>&nbsp;&nbsp;if(ord(substr($Modi_Str,$i,1))&gt;0xa0)&#123;<br/>&nbsp;&nbsp; if($mode)&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;$start++;<br/>&nbsp;&nbsp;&nbsp;&nbsp;$i++;<br/>&nbsp;&nbsp; &#125;<br/>&nbsp;&nbsp; $n++;<br/>&nbsp;&nbsp;&#125;<br/> &#125;<br/> if(!$mode)$start = $start + $n%2;<br/> $The_length = $start+$length;<br/> for($i=$start;$i&lt;$The_length;$i++)&#123; <br/>&nbsp;&nbsp;if(ord(substr($Modi_Str,$i,1))&gt;0xa0)&#123; <br/>&nbsp;&nbsp; $The_Str.=substr($Modi_Str,$i,2); <br/>&nbsp;&nbsp; $i++;<br/>&nbsp;&nbsp; if($mode) $The_length++;<br/>&nbsp;&nbsp;&#125;else&#123; <br/>&nbsp;&nbsp; $The_Str.=substr($Modi_Str,$i,1); <br/>&nbsp;&nbsp;&#125;<br/> &#125;<br/> return $The_Str;<br/>&#125;<br/><br/>/*<br/>以下两个函数为取得程序的执行时间，并可定制精确度（最多精确到 1E-10 s）<br/>*/<br/>function getmicrotime() &#123;<br/> if(function_exists(&quot;microtime&quot;)) &#123;<br/>&nbsp;&nbsp;list($usec, $sec) = explode(&quot; &quot;,microtime()); <br/>&nbsp;&nbsp;return $usec + $sec;<br/> &#125; else &#123;<br/>&nbsp;&nbsp;return time();<br/> &#125;<br/>&#125;<br/><br/>function gettimediff($time_start, $decimal = 3) &#123;<br/> $time_end = getmicrotime();<br/> $time = (string)($time_end - $time_start);<br/> $time = preg_replace(&quot;/^(&#91;&#92;d&#93;+.&#91;&#92;d&#93;&#123;&quot;.$decimal.&quot;&#125;)&#91;&#92;d&#93;*$/&quot;,&quot;&#92;&#92;1&quot;,$time);<br/> return $time;<br/>&#125;<br/><br/><br/>/*<br/>函数名：ob_handle<br/><br/>作 用：通过ob_start(&quot;ob_handle&quot;) 来处理缓存数据，并在 flush 前对其进行加工处理。<br/><br/>方 法：先设置 $ob_function 为函数名列表（以“;”作间隔，需均为字符串处理函数，且便两个数可为一，可以使自定义变量），再设置 ob_start(&quot;ob_handle&quot;) 调用本函数进行缓存控制，最后 ob_end_flush() 输出缓存。（注： $ob_function 在 ob_end_flush() 之前设置均有效！）<br/>*/<br/>$ob_function = &quot;htmlspecialchars;trim&quot;;<br/>function ob_handle ($content) &#123;<br/> //Coded By Windy_sk 20030510 v1.0<br/><br/> global $ob_function, $cache_file;<br/> $f_list = split(&quot;;&quot;, $ob_function);<br/> for($i=0; $i&lt;count($f_list); $i++) &#123;<br/>&nbsp;&nbsp;$temp = trim($f_list&#91;$i&#93;);<br/>&nbsp;&nbsp;if(function_exists($temp)) $content = $temp($content);<br/> &#125;<br/> if(phpversion() &gt; &quot;4.0.6&quot;) $content = ob_gzhandler($content, 1);<br/> return $content;<br/>&#125;<br/><br/><br/>/*<br/>函数名：RndKey<br/><br/>作 用：生成规定长度的随机字串<br/><br/>方 法：RndKey(8) -&gt; &quot;1d@5cDO(&quot;<br/>*/<br/>function RndKey($lng)&#123;<br/> $char_list = array();<br/> $char_list&#91;&#93; = &quot;1234567890&quot;;<br/> $char_list&#91;&#93; = &quot;ABCDEFGHIJKLMNOPQRSTUVWXYZ&quot;;<br/> $char_list&#91;&#93; = &quot;abcdefghijklmnopqrstuvwxyz&quot;;<br/> $char_list&#91;&#93; = &quot;!@^()_:+&#92;-&quot;;<br/> $char_length = count($char_list);<br/> $Rnd_Key = &quot;&quot;;<br/> for($i=1; $i&lt;=$lng; $i++)&#123;<br/>&nbsp;&nbsp;$Rnd_Str = $char_list&#91;rand(1,$char_length) - 1&#93;;<br/>&nbsp;&nbsp;$Rnd_Key .= substr($Rnd_Str, rand(0,strlen($Rnd_Str)-1), 1);<br/> &#125;<br/> return($Rnd_Key);<br/>&#125;<br/><br/>/*<br/>函数名：cut_words<br/><br/>作 用：将连续的文本按照全角字符和半角单词拆分<br/>*/<br/><br/> function cut_words($str) &#123;<br/> //Coded By Windy_sk 20020805 v1.0<br/><br/> $str = str_replace(&quot;&#92;r&#92;n&quot;,&quot;&#92;n&quot;,$str) . &quot; &quot;;<br/> preg_match_all(&quot;/&#91;&#92;xa0-&#92;xff&#93;?./&quot;, $str, $arr1);<br/> $arr1 = $arr1&#91;0&#93;;<br/> $arr2 = array();<br/> $n = 0;<br/> for($i=0; $i&lt;count($arr1); $i++) &#123;<br/>&nbsp;&nbsp;if(ord($arr1&#91;$i&#93;)&gt;=0xa0) &#123;<br/>&nbsp;&nbsp; if(!empty($arr2&#91;$n&#93;)) $n++;<br/>&nbsp;&nbsp; $arr2&#91;$n++&#93; = $arr1&#91;$i&#93;;<br/>&nbsp;&nbsp;&#125; elseif(preg_match(&quot;/&#92;s/m&quot;, $arr1&#91;$i&#93;)) &#123;<br/>&nbsp;&nbsp; $arr2&#91;++$n&#93; = $arr1&#91;$i&#93;;<br/>&nbsp;&nbsp;&#125; else &#123;<br/>&nbsp;&nbsp; $arr2&#91;$n&#93; .= $arr1&#91;$i&#93;;<br/>&nbsp;&nbsp;&#125;<br/> &#125;<br/> return join(&quot;&quot;, $arr2);<br/>&#125;<br/>?&gt;</div><br/>来源：http://blog.chinaunix.net/u2/84280/showart_2342810.html
]]>
</description>
</item><item>
<link>http://www.jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] PHP常用函数集合]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>