当前位置: 首页>>代码示例>>PHP>>正文


PHP JS::_PWC方法代码示例

本文整理汇总了PHP中JS::_PWC方法的典型用法代码示例。如果您正苦于以下问题:PHP JS::_PWC方法的具体用法?PHP JS::_PWC怎么用?PHP JS::_PWC使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JS的用法示例。


在下文中一共展示了JS::_PWC方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _pack_analyze

 private static function _pack_analyze($script, $regexp, $encode)
 {
     $wall = array();
     // all words in the script
     // get all words
     preg_match_all($regexp, $script, $wall);
     // simulate the javascript comportement of global match
     $wall = $wall[0];
     if (empty($wall)) {
         return false;
     }
     $wsort = array();
     // list of words sorted by frequency
     $wusrt = array();
     // list of words without sorting
     $wprot = array();
     // instances of "protected" words
     $wenco = array();
     // dictionary of word->encoding
     $dprot = array();
     // dictionary of word->"word"
     $value = array();
     // dictionary of charCode->encoding (eg. 256->ff)
     self::$_PWC = array();
     // word->count
     $i = count($wall);
     $j = 0;
     //$word = null;
     // count the occurrences - used for sorting later
     do {
         --$i;
         $word = '$' . $wall[$i];
         if (!isset(self::$_PWC[$word])) {
             self::$_PWC[$word] = 0;
             $wusrt[$j] = $word;
             // make a dictionary of all of the protected words in this script
             //  these are words that might be mistaken for encoding
             $value[$j] = call_user_func(array('self', $encode), $j);
             $dprot['$' . $value[$j]] = $j++;
         }
         // increment the word counter
         self::$_PWC[$word]++;
     } while ($i > 0);
     // prepare to sort the word list, first we must protect
     //  words that are also used as codes. we assign them a code
     //  equivalent to the word itself.
     // e.g. if "do" falls within our encoding range
     //      then we store keywords["do"] = "do";
     // this avoids problems when decoding
     $i = count($wusrt);
     do {
         $word = $wusrt[--$i];
         if (isset($dprot[$word])) {
             $wsort[$dprot[$word]] = substr($word, 1);
             $iprot[$dprot[$word]] = true;
             self::$_PWC[$word] = 0;
         }
     } while ($i);
     // sort the words by frequency
     // Note: the javascript and php version of sort can be different :
     // in php manual, usort :
     // " If two members compare as equal,
     // their order in the sorted array is undefined."
     // so the final packed script is different of the Dean's javascript version
     // but equivalent.
     // the ECMAscript standard does not guarantee this behaviour,
     // and thus not all browsers (e.g. Mozilla versions dating back to at
     // least 2003) respect this.
     usort($wusrt, array('self', '_pack_sortwords'));
     $j = 0;
     // because there are "protected" words in the list
     //  we must add the sorted words around them
     do {
         if (!isset($wsort[$i])) {
             $wsort[$i] = substr($wusrt[$j++], 1);
         }
         $wenco[$wsort[$i]] = $value[$i];
     } while (++$i < count($wusrt));
     return array('sorted' => $wsort, 'encoded' => $wenco, 'protected' => $wprot);
 }
开发者ID:hectormenendez,项目名称:h23,代码行数:80,代码来源:js.php


注:本文中的JS::_PWC方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。