解包数据
@param $str
@return array
197571
function unpack($str)
    {
        $data = array();
        foreach ($this->fileds as $k => $field)
        {
            /**
             * @var $field Field
             */
            switch ($field->type)
            {
                case Field::INT:
                    switch ($field->size)
                    {
                        case 1:
                            list(, $data[$k]) = unpack($field->signed ? 'c' : 'C', $str);
                            break;
                        case 2:
                            if ($this->convertBigEndian)
                            {
                                //网络字节序只有无符号的编码方式
                                list(, $data[$k]) = unpack('n', $str);
                            }
                            else
                            {
                                list(, $data[$k]) = unpack($field->signed ? 's' : 'S', $str);
                            }
                            break;
                        case 4:
                            if ($this->convertBigEndian)
                            {
                                //网络字节序只有无符号的编码方式
                                list(, $data[$k]) = unpack('N', $str);
                            }
                            else
                            {
                                list(, $data[$k]) = unpack($field->signed ? 'l' : 'L', $str);
                            }
                            break;
                        case 8:
                            if ($this->convertBigEndian)
                            {
                                //网络字节序只有无符号的编码方式
                                list(, $data[$k]) = unpack('J', $str);
                            }
                            else
                            {
                                list(, $data[$k]) = unpack($field->signed ? 'q' : 'Q', $str);
                            }
                            break;
                        default:
                            break;
                    }
                    break;
                case Field::FLOAT:
                    list(, $data[$k]) = unpack($field->size == 4 ? 'f' : 'd', $str);
                    break;
                case Field::CHAR:
                    $data[$k] = substr($str, 0, strpos($str, "\0"));
                    break;
                case Field::STRUCT:
                    $data[$k] = $field->struct->unpack($str);
                    break;
                default:
                    break;
            }
            $str = substr($str, $field->size);
        }
        return $data;
    }
17556
static public function toJson($str)
    {
        $data = \json_decode($str, true);

        switch (json_last_error()) {
            case JSON_ERROR_NONE:
            	return $data;
	        case JSON_ERROR_DEPTH:
	            return array('error' => 'Maximum stack depth exceeded');
	        case JSON_ERROR_STATE_MISMATCH:
	            return array('error' => 'Underflow or the modes mismatch');
	        case JSON_ERROR_CTRL_CHAR:
	            return array('error' => 'Unexpected control character found');
	        case JSON_ERROR_SYNTAX:
	            return array('error' => 'Syntax error, malformed JSON');
	        case JSON_ERROR_UTF8:
	            return array('error' => 'Malformed UTF-8 characters, possibly incorrectly encoded');
	        default:
	            return array('error' => 'Unknown error on JSON file');
        }
    }
1083420
private static function dealStr($str){
		$res = explode(self::$separate,$str);//空格分隔
        $str_time = preg_replace(self::$timeRegx,'',$res[self::$timeLine-1]);
        $date_time = \DateTime::createFromFormat(self::$timeFromat,$str_time,(new \DateTimeZone('Asia/Shanghai')));
        if ($date_time){
            $timestamp  = $date_time->getTimestamp();
        }else{
            throw new Exception("时间格式化有问题");
        }
        $t = $timestamp;
		$flow = $res[self::$flowLine-1]??0;//流量
		self::compareTime($t,$flow);
	}
428562
public function getErrors ($str = FALSE)
	{
		
		// Copy the errors array
		
		$errors	= $this->errors;
		
		// Reset errors
		
		$this->resetErrors ();
		
		// If return as string
		
		if ($str)
		{
			
			// Convert to string and return
			
			return implode ('<br />', $errors);
			
		}
		
		// Else
		
		else
		{
			
			// Return the errors array
			
			return $errors;
			
		}
		
	}
16520
protected function strtoupper($str)
    {
        $str = html_entity_decode($str, $this->htmlFuncFlags, self::ENCODING);
        $str = mb_strtoupper($str);
        $str = htmlspecialchars($str, $this->htmlFuncFlags, self::ENCODING);

        return $str;
    }
368477
public static function stringToArray($str)
    {
        $arr = [];

        for ($i = 0; $i < self::stringLength($str); $i++) {
            $arr[] = function_exists('mb_substr') ? mb_substr($str, $i, 1) : $str[$i];
        }

        return $arr;
    }
1346646
protected function parse($str)
    {
        $count = preg_match_all($this->tags->regex(), $str, $matches);

        // If we didn't find anything, return the string right back
        if (!$count || !is_array($matches)) {
            return $str;
        }

        // All we want is the array of actual strings matched
        $matches = reset($matches);

        return $this->parseTags($str, $matches);
    }
1372079
static public function resolveNginxStatus($str)
    {
        preg_match_all('/\d+/is', $str, $matched);
        if (count($matched[0]) === 7) {
            return [
                'connections' => (int)$matched[0][0],
                'accepts' => (int)$matched[0][1],
                'handled' => (int)$matched[0][2],
                'requests' => (int)$matched[0][3],
                'reading' => (int)$matched[0][4],
                'writing' => (int)$matched[0][5],
                'waiting' => (int)$matched[0][6]
            ];
        }

        return null;
    }
892133
protected function _getDomains($str)
    {
        $domains = array();
        $str = trim($str);
        if (strlen($str)) {
            $str = array_map('trim', preg_split("%[^a-z\-\d\.]+%", strtolower($str)));
            foreach ($str as $domain) {
                if (strlen($domain)) {
                    $domains[] = $domain;
                }
            }
        }
        return $domains;
    }
1157186
private function parse_all(&$str)
    {
        // php include
//         $str = preg_replace ( "/\{include\s+(.+)\}/", "<?php include \\1;?\>", $str );
        
        // php code, 内容分析到 '}', 可能会有问题？
        $str = preg_replace ( "/\{php\s+([^\}]+)\}/", "<?php \\1?>", $str );
        
        // if else
        $str = preg_replace ( "/\{if\s+(.+?)\}/", "<?php if(\\1) { ?>", $str );
        $str = preg_replace ( "/\{else\}/", "<?php } else { ?>", $str );
        $str = preg_replace ( "/\{elseif\s+(.+?)\}/", "<?php } elseif (\\1) { ?>", $str );
        $str = preg_replace ( "/\{\/if\}/", "<?php } ?>", $str );
        
        // for : {for($i=1; $i<10; $i++)}
        $str = preg_replace("/\{for\s+\(?(.+?)\)?\}/","<?php for(\\1) { ?>", $str);
        $str = preg_replace("/\{\/for\}/", "<?php } ?>", $str);
        
        // foreach : 
        // 1. {foreach($array as [$key=>] $value)}
        // 2. {foreach $array $value}
        // 3. {foreach $array $key $value}
        $str = preg_replace("/\{(foreach|loop)\s+\(((\S+).+?)\)\}/","<?php if(isset(\\3) && is_array(\\3)) foreach(\\2) { ?>", $str);
        $str = preg_replace("/\{(foreach|loop)\s+(\S+)\s+(?:as\s+)*(\S+)\}/", "<?php if(isset(\\2) && is_array(\\2)) foreach(\\2 as \\3) {?>", $str );
        $str = preg_replace("/\{(foreach|loop)\s+(\S+)\s+(?:as\s+)*(\S+)\s+(\S+)\}/", "<?php if(isset(\\2) && is_array(\\2)) foreach(\\2 as \\3 => \\4){?>", $str );
        $str = preg_replace("/\{\/(foreach|loop)\}/", "<?php } ?>", $str );
        
        // ++ --
        $str = preg_replace("/\{\+\+(.+?)\}/", "<?php ++\\1; ?>", $str);
        $str = preg_replace("/\{\-\-(.+?)\}/", "<?php ++\\1; ?>", $str);
        $str = preg_replace("/\{(.+?)\+\+\}/", "<?php \\1++; ?>", $str);
        $str = preg_replace("/\{(.+?)\-\-\}/", "<?php \\1--; ?>", $str);
        
        // {widget:name action='method'...}  调用标签方法
        $str = preg_replace_callback("/\{widget:?([\w\:]+)?\s+([^}]+)\}/i", array($this,'widget_callback'), $str);
        $str = preg_replace_callback("/\{\/widget[^}]*\}/i", array($this, 'end_widget_callback'), $str);
        
        // include sub template: {include 'header'}
        $str = preg_replace_callback( "/\{(template|include|layout)\s+(.+)\}/", array($this, 'parse_callback'), $str );
        
        // function or var: {function(...)} or {$data}
        $str = $this->parse_fun_var($str);
        
        // add permission
        
        return $str;
    }
481455
private function getHeaders($str) {
    $str = explode(self::LE . self::LE, $str);
    $str = reset($str);
    $str = explode(self::LE, $str);
    $new = array();
    $s = 1;
    foreach ($str as $line) {
      $pos = strpos($line, ': ');
      if ($pos !== false) {
        $key = strtolower(substr($line, 0, $pos));
        if (!isset($new[$key])) {
          $new[$key] = preg_replace('/\s+/', ' ', trim(substr($line, $pos+1)));
        }
        else {
          $new[$key.'-'.$s] = preg_replace('/\s+/', ' ', trim(substr($line, $pos+1)));
          $s++;
        }
      }
      else {
        $new['status'] = $line; # HTTP/1.1 200 OK
      }
    }
    return $new;
  }
470051
protected function _fromSequenceString($str)
    {
        $ids = array();
        $str = trim($str);

        if (!strlen($str)) {
            return $ids;
        }

        $idarray = explode(',', $str);

        foreach ($idarray as $val) {
            $range = explode(':', $val);
            if (isset($range[1])) {
                for ($i = min($range), $j = max($range); $i <= $j; ++$i) {
                    $ids[] = $i;
                }
            } else {
                $ids[] = $val;
            }
        }

        return $ids;
    }
1217866
public static function utf7_to_utf8($str)
    {
        $Index_64 = array(
            0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
            0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
            0,0,0,0, 0,0,0,0, 0,0,0,1, 0,0,0,0,
            1,1,1,1, 1,1,1,1, 1,1,0,0, 0,0,0,0,
            0,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1,
            1,1,1,1, 1,1,1,1, 1,1,1,0, 0,0,0,0,
            0,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1,
            1,1,1,1, 1,1,1,1, 1,1,1,0, 0,0,0,0,
        );

        $u7len = strlen($str);
        $str   = strval($str);
        $res   = '';

        for ($i=0; $u7len > 0; $i++, $u7len--) {
            $u7 = $str[$i];
            if ($u7 == '+') {
                $i++;
                $u7len--;
                $ch = '';

                for (; $u7len > 0; $i++, $u7len--) {
                    $u7 = $str[$i];

                    if (!$Index_64[ord($u7)]) {
                        break;
                    }

                    $ch .= $u7;
                }

                if ($ch == '') {
                    if ($u7 == '-') {
                        $res .= '+';
                    }

                    continue;
                }

                $res .= self::utf16_to_utf8(base64_decode($ch));
            }
            else {
                $res .= $u7;
            }
        }

        return $res;
    }
1324055
private function getDiscreteText($str) {
        $arr = array();
        for ( $i = 0; $i < strlen($str); $i++ ) {
            if ( $str[$i] == "\n" ) continue;
            if ( ord($str[$i]) < 127 ) {
                array_push($arr, $str[$i]);
                continue;
            }
            if ( ord($str[$i]) > 127 &&
                ord($str[$i+1]) > 127 &&
                ord($str[$i+2]) > 127 ) {
                array_push($arr, substr($str, $i, 3));
                $i += 2;
            }
        }
        return $arr;
    }
550025
private function parseLine($str, $color = null)
    {
        $parsed = [];
        $lines = explode(PHP_EOL, $str);
        $last = count($lines) - 1;
        foreach ($lines as $key => $line) {
            $parsed[] = [
                'colored' => $color ? sprintf("\033[%sm%s\033[0m", $color, $line) : $line,
                'original' => $line,
                'newline' => $key < $last
            ];
        }

        return $parsed;
    }
167523
protected function parseDatabaseStats($str)
    {
        $db = array();

        foreach (explode(',', $str) as $dbvar) {
            list($dbvk, $dbvv) = explode('=', $dbvar);
            $db[trim($dbvk)] = $dbvv;
        }

        return $db;
    }
315973
protected function extractNodeFromBBCode($str)
    {
        $references = array();
        /** @var \OpenOrchestra\BBcodeBundle\Parser\BBcodeParserInterface $parserBBcode */
        $parsedBBcode = $this->bbcodeParser->parse($str);
        $nodeTags = $parsedBBcode->getElementByTagName(InternalLinkDefinition::TAG_NAME);
        /** @var \OpenOrchestra\BBcodeBundle\ElementNode\BBcodeElementNodeInterface $mediaTag */
        foreach ($nodeTags as $nodeTag) {
            $linkAttribute = json_decode(html_entity_decode($nodeTag->getAttribute()['link']), true);
            $nodeId = $linkAttribute['site']['nodeId'];
            $siteId = $linkAttribute['site']['siteId'];
            $references[] = array('nodeId' => $nodeId, 'siteId' => $siteId);
        }
        return $references;
    }