Extracts the statistics of each logical DB from the string buffer.

@param string $str Response buffer.

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

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

        return $db;
    }
916235
protected function extractContentIdFromBBCode($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);
            if (!empty($linkAttribute['contentSearch_contentId'])) {
                $references[] = $linkAttribute['contentSearch_contentId'];
            }
        }

        return $references;
    }
828492
public static function getString(&$str)
    {
        $p = mb_orig_strpos($str, "\x00");
        if ($p === false) {
            return '';
        }
        $r = mb_orig_substr($str, 0, $p);
        $str = mb_orig_substr($str, $p + 1);
        return $r;
    }
1367075
private function header2Array($str)
    {
        if (is_array($str)) return $str;
        
        $result = [];
        $array = explode("\n", trim(str_replace("\r\n", "\n", $str), "\n"));
        foreach($array as $i => $line) {
            if ($i === 0) {
                $result['Http-Status'] = $line; // "HTTP/1.1 200 OK"
            } else {
                $header = explode(':', $line, 2);
                if (!$header[0]) continue;
                
                if (isset($header[1])) {
                    $result[trim($header[0])] = trim($header[1]);
                } else {
                    $result[] = trim($header[0]);
                }
            }
        }
        return $result;
    }
58462
public function detect(string $str): LanguageResult
    {
        $str = mb_strtolower($str);

        $samples = $this->getNgrams($str);

        $result = [];

        if (count($samples) > 0)
        {
            foreach ($this->tokens as $lang => $value)
            {
                $index = $sum = 0;
                $value = array_flip($value);

                foreach ($samples as $v)
                {
                    if (isset($value[$v]))
                    {
                        $x = $index++ - $value[$v];
                        $y = $x >> (PHP_INT_SIZE * 8);
                        $sum += ($x + $y) ^ $y;
                        continue;
                    }

                    $sum += $this->maxNgrams;
                    ++$index;
                }

                $result[$lang] = 1 - ($sum / ($this->maxNgrams * $index));
            }

            arsort($result, SORT_NUMERIC);
        }

        return new LanguageResult($result);
    }
979581
protected function checkAr($str) 
    {
        $lines  = $this->_arLogodd;
        $logodd = array();
        
        $line   = array_shift($lines);
        $line   = rtrim($line);
        $second = preg_split("/\t/", $line);
        $temp   = array_shift($second);
        
        foreach ($lines as $line) {
            $line   = rtrim($line);
            $values = preg_split("/\t/", $line);
            $first  = array_shift($values);
            
            for ($i=0; $i<37; $i++) {
                $logodd["$first"]["{$second[$i]}"] = $values[$i];
            }
        }
        
        $max  = mb_strlen($str, 'UTF-8');
        $rank = 0;
        
        for ($i=1; $i<$max; $i++) {
            $first  = mb_substr($str, $i-1, 1, 'UTF-8');
            $second = mb_substr($str, $i, 1, 'UTF-8');
     
            if (isset($logodd["$first"]["$second"])) {
                $rank += $logodd["$first"]["$second"]; 
            } else {
                $rank -= 10;
            }
        }

        return $rank;
    }
205491
public static function getRawData($data_str)
    {
        if (is_string($data_str) && ($data_str=="''" || $data_str=='""')) {
            $data = '';
        } else {
            $data = $data_str;
        }

        if (!empty($data) && ($data{0} == '{' || $data{0} == '[')) {
            try {
                $data = self::json_decode($data);
            } catch (\Exception $e) {
                throw $e;
            }
        }

        return $data;
    }
1197543
public function parse($str)
	{
		$str      = str_replace("\r", "", $str);
		$len      = strlen($str);
		$tag_open = false;
		$tag_text = '';
		$tag      = '';

		// set the document as the current tag.
		$this->current_tag = $this;

		for($i=0; $i<$len; ++$i)
		{
			if($str[$i] === '[')
			{
				if($tag_open)
					$tag_text .= '[' . $tag;

				$tag_open = true;
				$tag      = '';
			}
			else if($str[$i] === ']' && $tag_open)
			{
				if($tag !== '')
				{
					$bits        = preg_split('/([ =])/', trim($tag), 2, PREG_SPLIT_DELIM_CAPTURE);
					$tag_attrs   = (isset($bits[2]) ? $bits[1] . $bits[2] : '');
					$tag_closing = ($bits[0][0] === '/');
					$tag_name    = ($bits[0][0] === '/' ? substr($bits[0], 1) : $bits[0]);

					if(isset($this->bbcodes[$tag_name]))
					{
						$this->tag_text($tag_text);
						$tag_text = '';

						if($tag_closing)
						{
							if(!$this->tag_close($tag_name))
								$tag_text = "[{$tag}]";
						}
						else
						{
							if(!$this->tag_open($tag_name, $this->parse_attribs($tag_attrs)))
								$tag_text = "[{$tag}]";
						}
					}
					else
						$tag_text .= "[{$tag}]";
				}
				else
					$tag_text .= '[]';

				$tag_open = false;
				$tag      = '';
			}
			else if($tag_open)
				$tag .= $str[$i];
			else
				$tag_text .= $str[$i];
		}

		$this->tag_text($tag_text);

		if($this->throw_errors && !$this->current_tag instanceof Node_Container_Document)
			throw new Exception_MissingEndTag("Missing closing tag for tag [{$this->current_tag->tag()}]");

		return $this;
	}
1014774
public static function str_split($str, $split_len = 1)
    {
        if (! preg_match('/^[0-9]+$/', $split_len) || $split_len < 1) {
            return false;
        }

        $len = AnHelperString::strlen($str);
        if ($len <= $split_len) {
            return array($str);
        }

        preg_match_all('/.{'.$split_len.'}|[^\x00]{1,'.$split_len.'}$/us', $str, $ar);
        return $ar[0];
    }
1320526
public static function DecodePgArray(string $str) :array
        {
            if ($str == '{}' || $str[0] != '{' || $str[-1] != '}') {
                return [];
            }

            $nestLevel = -1;
            $res       = [];
            $len       = strlen($str);
            $item      = "";

            for ($i = 0; $i < $len; $i++) {
                if ($str[$i] == "{") {
                    if (++$nestLevel > 0) {
                        $item .= $str[$i];
                    }
                }
                else if ($str[$i] == "}") {
                    if ($nestLevel-- > 0) {
                        $item .= $str[$i];
                    }

                    if ($nestLevel == -1) {
                        if (is_numeric($item)) {
                            $item = $item * 1;
                        }
                        else if ($item[0] == "{") {
                            $item = self::DecodePgArray($item);
                        }
                        else {
                            $item = trim($item, "\"");
                        }

                        $res[] = $item;
                        $item  = '';
                    }
                }
                else if ($str[$i] == ',' && !$nestLevel) {
                    if (is_numeric($item)) {
                        $item = $item * 1;
                    }
                    else if ($item[0] == "{") {
                        $item = self::DecodePgArray($item);
                    }
                    else {
                        $item = trim($item, "\"");
                    }

                    $res[] = $item;
                    $item  = '';
                }
                else {
                    $item .= $str[$i];
                }
            }

            return $res;
        }
152420
public static function parse_attrib_string($str)
    {
        $attrib = array();
        $html   = '<html>'
            . '<head><meta http-equiv="Content-Type" content="text/html; charset=' . RCUBE_CHARSET . '" /></head>'
            . '<body><div ' . rtrim($str, '/ ') . ' /></body>'
            . '</html>';

        $document = new DOMDocument('1.0', RCUBE_CHARSET);
        @$document->loadHTML($html);

        if ($node = $document->getElementsByTagName('div')->item(0)) {
            foreach ($node->attributes as $name => $attr) {
                $attrib[strtolower($name)] = $attr->nodeValue;
            }
        }

        return $attrib;
    }
1007430
public static function parse($str)
    {
        $bLength = 0;
        if ('b' === $str[0]) {
            $bLength = 1;
        }

        if ('\'' === $str[$bLength]) {
            return str_replace(
                ['\\\\', '\\\''],
                ['\\', '\''],
                substr($str, $bLength + 1, -1)
            );
        } else {
            return self::parseEscapeSequences(substr($str, $bLength + 1, -1), '"');
        }
    }
816789
public function parseString($str) {
        if (!extension_loaded("SimpleXML"))
            throw new XmlParserException("SimpleXML extension not loaded, can not parse XML");
        
        libxml_use_internal_errors(true);
        $xml = simplexml_load_string($str);
        
        if ($xml === false) {
            $msg = "The following XML errors occurred while parsing:";
            foreach (libxml_get_errors() as $error)
                $msg .= "\n" . $error->message;
            throw new XmlParserException($msg);
        }

        $this->xml = $xml;
        $this->xmlString = $str;
        return $this;
    }
835641
static public function fromCamel($str) {
      $str[0] = strtolower($str[0]);
      return preg_replace_callback('/([A-Z])/', function($char) {return "_" . strtolower($char[1]);}, $str);
  }
640853
public function findAll($str) {
        $this->recvAll();
        $output_as_array = explode($this->retcarriage, $this->getBuffer());
        foreach ($output_as_array as $line) {
            if (preg_match("/{$str}/", $line, $matches)) {
                return $matches[0];
            }
        }
        return false;
    }
99027
public static function courseCode($str)
    {
        $pattern = '/(\d+-\d+)-(\d)\)-([^-]+)-([^-]+)-(\d+)/';

        $ret = [];
        if (preg_match($pattern, $str, $matches)) {
            $ret = [
                'year'               => $matches[1],
                'term'               => $matches[2],
                'code'               => $matches[3],
                'teacher_job_number' => $matches[4],
                'no'                 => $matches[5],
            ];
        }

        return $ret;
    }
170971
public static function get(string $str):array
    {
        $str = trim($str);
        $strArr = Str::toArray($str);
        $results = [];
        foreach ($strArr as $s) {
            $results[] = self::getSingle($s);
        }
        return $results;
    }