<?xml version="1.0" encoding="UTF-8"?> <rss
version="0.92"> <channel><title>代码收藏</title><link>http://code.9enjoy.com</link> <description>收集网站开发时常用到的代码(asp,php,js等)，以函数为主</description> <lastBuildDate>Wed, 12 May 2010 13:51:08 +0000</lastBuildDate> <docs>http://backend.userland.com/rss092</docs> <language>en</language> <item><title>去掉 HTML 标记，javascript 代码</title> <description><![CDATA[function trip_html( $html, $len ) {
// $html 应包含一个 HTML 文档。
// 本例将去掉 HTML 标记，javascript 代码
// 和空白字符。还会将一些通用的
// HTML 实体转换成相应的文本。
$search = array (&#8220;&#8216;&#60;script[^&#62;]*?&#62;.*?&#60;/script&#62;&#8217;si&#8221;,  // 去掉 javascript
&#8220;&#8216;&#60;[\/\!]*?[^&#60;&#62;]*?&#62;&#8217;si&#8221;,           // 去掉 HTML 标记
&#8220;&#8216;([\r\n])[\s]+&#8217;&#8221;,                 // 去掉空白字符
&#8220;&#8216;&#38;(quot&#124;#34);&#8217;i&#8221;,                 // 替换 HTML 实体
&#8220;&#8216;&#38;(amp&#124;#38);&#8217;i&#8221;,
&#8220;&#8216;&#38;(lt&#124;#60);&#8217;i&#8221;,
&#8220;&#8216;&#38;(gt&#124;#62);&#8217;i&#8221;,
&#8220;&#8216;&#38;(nbsp&#124;#160);&#8217;i&#8221;,
&#8220;&#8216;&#38;(iexcl&#124;#161);&#8217;i&#8221;,
&#8220;&#8216;&#38;(cent&#124;#162);&#8217;i&#8221;,
&#8220;&#8216;&#38;(pound&#124;#163);&#8217;i&#8221;,
&#8220;&#8216;&#38;(copy&#124;#169);&#8217;i&#8221;,
&#8220;&#8216;&#38;#(\d+);&#8217;e&#8221;);                    // 作为 PHP 代码运行
$replace = array (&#8220;&#8221;,
&#8220;&#8221;,
&#8220;\\1&#8243;,
&#8220;\&#8221;",
&#8220;&#38;&#8221;,
&#8220;&#60;&#8221;,
&#8220;&#62;&#8221;,
&#8220; &#8221;,
chr(161),
chr(162),
chr(163),
chr(169),
&#8220;chr(\\1)&#8221;);
$text = preg_replace ($search, $replace, $html);
$text = trim($text);
return mb_strlen($text) &#62;= $len ? mb_substr($text, 0, $len) : &#8221;;
}
]]></description><link>http://code.9enjoy.com/php/trip_html/</link> </item> <item><title>ASP来实现UTF8转换GB2312国标码</title> <description><![CDATA[ASP来实现UTF8转换GB2312国标码-GB2312转UTF-8
&#8216;个人代码风格注释（变量名中第一个小写字母表表示变量类型）
&#8216;i:为Integer型;
&#8217;s:为String;
Function U2UTF8(Byval a_iNum)
    Dim sResult,sUTF8
    Dim iTemp,iHexNum,i
    iHexNum = Trim(a_iNum)
    If iHexNum = &#8220;&#8221; Then
        Exit Function
    End If
    sResult = &#8220;&#8221;
    If (iHexNum &#60; 128) Then
        sResult = sResult &#38; iHexNum
    ElseIf (iHexNum &#60; 2048) Then
        sResult = ChrB(&#38;H80 + (iHexNum And &#38;H3F))
        iHexNum = iHexNum \ &#38;H40
        sResult = ChrB(&#38;HC0 + (iHexNum And [...]]]></description><link>http://code.9enjoy.com/asp/gb2utf8/</link> </item> <item><title>二维数组的array_unique函数</title> <description><![CDATA[关于php的array_unique函数，此函数只适用于一维数组，对多维数组并不适用，以下提供一个二维数组的array_unique函数 
//二维数组去掉重复值
function array_unique_fb($array2D){  
     foreach ($array2D as $v){
         $v = join(&#8220;,&#8221;,$v);              //降维,也可以用implode,将一维数组转换为用逗号连接的字符串
         $temp[] = $v;
     }
     $temp = array_unique($temp);      //去掉重复的字符串,也就是重复的一维数组
    foreach ($temp as $k =&#62; $v){
        $temp[$k] = explode(&#8220;,&#8221;,$v);       //再将拆开的数组重新组装
    }
    return $temp;
}
原文：http://blog.sina.com.cn/s/blog_60c5cbf50100e4qz.html
]]></description><link>http://code.9enjoy.com/php/array_unique_fb/</link> </item> <item><title>GBK的页面输出JSON</title> <description><![CDATA[encode之前转换为utf-8,decode之后转回gbk:
function tb_json_encode($value, $options = 0)
{
  return json_encode(tb_json_convert_encoding($value, &#8220;GBK&#8221;, &#8220;UTF-8&#8243;));
}
function tb_json_decode($str, $assoc = false, $depth = 512)
{
  return tb_json_convert_encoding(json_decode($str, $assoc), &#8220;UTF-8&#8243;, &#8220;GBK&#8221;);
}
function tb_json_convert_encoding($m, $from, $to)
{
  switch(gettype($m)) {
    case &#8216;integer&#8217;:
    case &#8216;boolean&#8217;:
    case &#8216;float&#8217;:
    case &#8216;double&#8217;:
    case &#8216;NULL&#8217;:
      return $m;
    case &#8217;string&#8217;:
      return mb_convert_encoding($m, $to, $from);
    case &#8216;object&#8217;:
      $vars = array_keys(get_object_vars($m));
      foreach($vars as $key) {
        $m-&#62;$key = [...]]]></description><link>http://code.9enjoy.com/php/gbk-json/</link> </item> <item><title>文本转HTML</title> <description><![CDATA[//文本转HTML
function Text2Html($txt)
{
$txt = str_replace(&#8221;  &#8221;,&#8221;　&#8221;,$txt);
$txt = str_replace(&#8220;&#60;&#8221;,&#8221;&#38;lt;&#8221;,$txt);
$txt = str_replace(&#8220;&#62;&#8221;,&#8221;&#38;gt;&#8221;,$txt);
$txt = preg_replace(&#8220;/[\r\n]{1,}/isU&#8221;,&#8221;&#60;br/&#62;\r\n&#8221;,$txt);
return $txt;
}
]]></description><link>http://code.9enjoy.com/php/text-to-html/</link> </item> <item><title>在字符串指定位置插入一段字符串</title> <description><![CDATA[//插入一段字符串
function str_insert($str, $i, $substr)
{
for($j=0; $j&#60;$i; $j++){
$startstr .= $str[$j];
}
for ($j=$i; $j&#60;strlen($str); $j++){
$laststr .= $str[$j];
}
$str = ($startstr . $substr . $laststr);
return $str;
}]]></description><link>http://code.9enjoy.com/php/str_insert/</link> </item> <item><title>php数组二分法查找</title> <description><![CDATA[&#60;?php
//search函数 其中$array为数组，$k为要找的值，$low为查找范围的最小键值，$high为查找范围的最大键值
function search($array, $k, $low=0, $high=0)
{
if(count($array)!=0 and $high == 0)                 //判断是否为第一次调用
{
$high = count($array);
}
if($low &#60;= $high)                                //如果还存在剩余的数组元素
{
$mid = intval(($low+$high)/2);                  //取$low和$high的中间值
if ($array[$mid] == $k)     [...]]]></description><link>http://code.9enjoy.com/php/array-search/</link> </item> <item><title>正确获得访客IP</title> <description><![CDATA[正确获得访客IP]]></description><link>http://code.9enjoy.com/php/onlineip/</link> </item> <item><title>加强版htmlspecialchars</title> <description><![CDATA[加强版htmlspecialchars，可防止&#38;等特殊字符的&#038;被再次转换。]]></description><link>http://code.9enjoy.com/php/shtmlspecialchars/</link> </item> <item><title>支持数组的ADDSLASHES</title> <description><![CDATA[支持数组的ADDSLASHES]]></description><link>http://code.9enjoy.com/php/saddslashes/</link> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk
Database Caching 4/13 queries in 0.011 seconds using disk

Served from: code.itlearner.com @ 2010-09-09 16:54:41 -->