Parse email address string
@param  string $str       string input
@param  string $separator separator, default ","
@return array             array
426594
public static function parse_email($str, $separator = ",") {

        $str = trim(preg_replace('/\s+/', ' ', $str));
        $all = [];
        $emails = preg_split('/(".*?"\s*<.+?>)\s*' . $separator . '*|' . $separator . '+/', $str, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
        foreach ($emails as $email) {
            $name = "";
            $email = trim($email);
            $email_info = new stdClass;
            if (preg_match('/(.*?)<(.*)>/', $email, $regs)) {
                $email_info->name = trim(trim($regs[1]) , '"');
                $email_info->email = trim($regs[2]);
            } else {
                $email_info->name = $email;
                $email_info->email = $email;
            }

            if (strpos($email_info->email, $separator) !== false) {
                $addtl_emails = parse_email($email_info->email, $separator);
                foreach ($addtl_emails as $addtl_email_info) {
                    if ($addtl_email_info->name == "" || $addtl_email_info->name == $addtl_email_info->email) $addtl_email_info->name = $email_info->name;

                    $all[] = $addtl_email_info;
                }
            } else {
                if (filter_var($email_info->email, FILTER_VALIDATE_EMAIL)) $all[] = $email_info;
            }
        }
        return $all;
    }
128914
protected function _extractAttributes($str) {
		$str = preg_replace("/[\x{00a0}\x{200b}]+/u", ' ', $str);
		$attributes = array();
		$patterns = array(
			'name-value-quotes-dble' => '(\w+)\s*=\s*"([^"]*)"',
			'name-value-quotes-sgle' => "(\w+)\s*=\s*'([^']*)'",
			'name-value-quotes-none' => '(\w+)\s*=\s*([^\s\'"]+)',
			'name-quotes-dble' => '"([^"]*)"',
			'name-quotes-sgle' => "'([^']*)'",
			'name-quotes-none' => '(\w+)'
		);
		$pattern = '/' . implode('(?:\s|$)|', $patterns) . '(?:\s|$)/';

		if (!preg_match_all($pattern, $str, $matches, PREG_SET_ORDER)) {
			return $attributes;
		}

		foreach ($matches as $match) {
			if (!empty($match[1])) {
				$attributes[strtolower($match[1])] = stripcslashes($match[2]);
			} else if (!empty($match[3])) {
				$attributes[$match[3]] = stripcslashes($match[4]);
			} else if (!empty($match[5])) {
				$attributes[$match[5]] = stripcslashes($match[6]);
			} else if (!empty($match[7]) && strlen($match[7])) {
				$attributes[] = stripcslashes($match[7]);
			} else if (!empty($match[8])) {
				$attributes[] = stripcslashes($match[8]);
			} else if (!empty($match[9])) {
				$attributes[] = stripcslashes($match[9]);
			}
		}

		return $attributes;
	}
593019
public static function toArray($stringOrArray, string $separator = '.'): array
    {
        if (is_string($stringOrArray)) {
            if (trim($stringOrArray) !== '') {
                $stringOrArray = explode($separator, $stringOrArray);
            }
        }
        if (!is_array($stringOrArray)) {
            return [];
        }
        return $stringOrArray;
    }
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;
    }
1081348
public static List<String> split(String str, char sepChr) {
    	List<String> result = new ArrayList<String>();
    	int idx = 0;
    	while(true) {
    		int idx2 = str.indexOf(sepChr, idx);
    		if(idx2 < 0) {
    			result.add(str.substring(idx));
    			break;
    		}
    		result.add(str.substring(idx, idx2));
    		idx = idx2 + 1;
    	}
        return result;
    }
585006
static function proper_parse_str($str)
	{
		// result array
		$arr = array();

		// split on outer delimiter
		$pairs = explode('&', $str);

		// loop through each pair
		foreach ($pairs as $i)
		{
			// split into name and value
			list($name,$value) = explode('=', $i, 2);

			// if name already exists
			if( isset($arr[$name]) )
			{
				// stick multiple values into an array
				if( is_array($arr[$name]) )
					$arr[$name][] = $value;
				else
					$arr[$name] = array($arr[$name], $value);
			}
			// otherwise, simply stick it in a scalar
			else
				$arr[$name] = $value;
		}

		// return result array
		return $arr;
	}
624635
public static function decodeArray(String $data, String $key = NULL, String $separator = NULL) : Array
    {
        return (array) self::decode($data, $key, $separator);
    }
169592
protected static function parseAs($str, $alias1 = null) {
        $table = preg_split('#\b(as|\s+)\b#i', trim($str));
        if (count($table) == 1) {
            $name  = $table [0];
            $alias = $alias1;
        } else {
            $name  = $table [0];
            $alias = trim(array_pop($table));
        }

        return [trim($name), trim($alias)];
    }
874663
private function splitSegment(string &$str): array
    {
        // remove ending "symbEnd"
        $str = \trim(
            \preg_replace(
                self::$DELIMITER . $this->symbEnd . '$' . self::$DELIMITER,
                '',
                $str
            )
        );

        // replace duplicate "symbRel"
        $str = \str_replace(
            $this->symbUnescapedRel . $this->symbUnescapedRel,
            $this->stringSafe,
            $str
        );

        // split on "sepData" if not escaped (negative lookbehind)
        $matches = \preg_split(
            self::$DELIMITER . "(?<!" . $this->symbRel . ")" . $this->sepData . self::$DELIMITER,
            $str
        );
        // fallback
        if ($matches === false) {
            $matches = [];
        }

        foreach ($matches as &$value) {
            if ($value === '') {
                continue;
            }

            // INFO:
            //
            // ? immediately preceding one of the characters '+:? restores their normal meaning
            //
            // e.g. 10?+10=20 means 10+10=20
            //
            // Question mark is represented by ??

            if (\strpos($value, $this->symbEnd) !== false) {
                if (\preg_match(self::$DELIMITER . "(?<!" . $this->symbRel . ")" . $this->symbEnd . self::$DELIMITER, $value)) {
                    $this->errors[] = "There's a " . \stripslashes($this->symbEnd) . " not escaped in the data; string " . $str;
                }
            }

            if (\strpos($value, $this->symbUnescapedRel) !== false) {
                if (\preg_match(self::$DELIMITER . "(?<!" . $this->symbRel . ")" . $this->symbRel . "(?!" . $this->symbRel . ")(?!" . $this->sepData . ")(?!" . $this->sepComp . ")(?!" . $this->symbEnd . ")" . self::$DELIMITER, $value)) {
                    $this->errors[] = "There's a character not escaped with " . \stripslashes($this->symbRel) . " in the data; string " . $value;
                }
            }

            // split on "sepComp"
            $value = $this->splitData($value);
        }
        unset($value);

        return $matches;
    }
163535
private function split(string $str) {
        $len = strlen($str);
        for ($i = 0; $i < $len; $i++) {
            $c = $str[$i];
            $n = ord($c);
            if (($n >> 7) == 0) {
                //0xxx xxxx, asci, single
                yield $c;
            } elseif (($n >> 4) == 15) { //1111 xxxx, first in four char
                if ($i < $len - 3) {
                    yield $c . $str[$i + 1] . $str[$i + 2] . $str[$i + 3];
                    $i += 3;
                }
            } elseif (($n >> 5) == 7) {
                //111x xxxx, first in three char
                if ($i < $len - 2) {
                    yield $c . $str[$i + 1] . $str[$i + 2];
                    $i += 2;
                }
            } elseif (($n >> 6) == 3) {
                //11xx xxxx, first in two char
                if ($i < $len - 1) {
                    yield $c . $str[$i + 1];
                    $i++;
                }
            }
        }
    }
526492
private function parseHeaders($str) {

		if(false === is_string($str)) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($str)), E_USER_ERROR);
		}
		
		$headers = [];
		$status  = [];

		foreach(explode("\n", $str) as $header) {
			
			if(preg_match('/(:)/is', $header)) {
				list($key, $value) = preg_split('/(:)/is', $header, 2);
			}
			else {
				$key = $header;
			}

			if(trim($key) !== '') {

				if(preg_match('/(https?\/[0-9]\.[0-9])/i', $key, $http)) {

					$status['code'] = null;

					if(preg_match('/([0-9]+)/', ltrim($key, $http[0]), $code)) {
						$status['code'] = $code[0];
					}

					$status['protocol'] = $http[0];
					$status['status'] 	= trim($key);
					$status['text'] 	= trim(ltrim(trim(ltrim($key, $status['protocol'])), $status['code']));
					
				}
				else {
					$headers[strtolower($key)] = trim($value);
				}
			}
		}

		return ['headers' => $headers, 'status' => $status];
	}
821240
public static function extract($str)
    {
        preg_match_all("/(^|[\n ])#([a-z0-9_-]*)/is", $str, $matches);

        if (!is_array($matches) || !count($matches)) {
            return [];
        }

        $hashtags = [];
        foreach ($matches[0] as $match) {
            $match = ltrim(trim($match), '#_ ');
            if (self::isValid($match)) {
                $hashtags[strtolower($match)] = $match;
            }
        }

        return array_values($hashtags);
    }
722307
public static function convertStringToArray($str, $seperator = ',', $limit = PHP_INT_MAX)
    {
        return self::removeEmptyItems(explode($seperator, $str, $limit), function ($param) {
            return self::trimQuots($param);
        });
    }
50893
public static List<String> split(String str, String separatorChars)
  {
    final String[] array = StringUtils.split(str, separatorChars);

    return Arrays.asList(array);
  }
1196281
public static function fromString($string, $separator=' '){

        $string = (string)$string;

        if($separator === ''){
            return new StringList(str_split($string),'');
        }

        $prefix = '';
        $suffix = '';
        if($string[0] == $separator){
            $prefix = $separator;
        }
        if($string[strlen($string)-1] == $separator){
            $suffix = $separator;
        }
        $strList = new StringList(explode($separator,trim($string,$separator)),
                                          $separator);
        $strList->prefix = $prefix;
        $strList->suffix = $suffix;
        return $strList;
    }
110517
public function parse(string $str): Includes
    {
        // Ignore whitespace
        $str = preg_replace('/\s/', '', $str);

        if (empty($str)) {
            return new Includes();
        }

        // Parse a string in the following format:
        // pets{id,name,owner{id,name},photos:limit(3)}:limit(5):offset(10)

        // Define the current parse state
        $state = [
            // Original string
            'string' => $str,
            // Position in string
            'pos' => 0,
            // Length of the original string being processed
            'len' => 0,
            // Current character being processed
            'char' => null,
            // The accumulated current key for the field
            'buffer' => '',
            // The current parent keys
            'parent' => [],
            // Previous parent
            'prevParent' => null,
            // Our list of keys
            'keys' => [],
            // Our list of params
            'params' => [],
        ];

        // Process each character, moving through the state and build
        while ($state['pos'] < ($len = \strlen($str))) {
            $state['char'] = $str[$state['pos']];
            $state['len'] = $len;

            switch ($state['char']) {
                case '{':
                    // Begin children
                    if (!empty($state['buffer'])) {
                        $state['keys'][] = $this->prefixParentKeys($state['buffer'], $state['parent']);
                        $state['parent'][] = $state['buffer'];
                        $state['buffer'] = '';
                    }
                    break;
                case ',':
                    // Delimiter
                    if (!empty($state['buffer'])) {
                        $state['keys'][] = $this->prefixParentKeys($state['buffer'], $state['parent']);
                        $state['buffer'] = '';
                    }
                    break;
                case '}':
                    // End children
                    if (!empty($state['buffer'])) {
                        $state['keys'][] = $this->prefixParentKeys($state['buffer'], $state['parent']);
                        $state['buffer'] = '';
                    }
                    if (!empty($state['parent'])) {
                        $state['prevParent'] = $state['parent'];
                        array_pop($state['parent']);
                    }
                    break;
                case ':':
                    // Looks like it's a parameter. Eg. :limit(10)
                    // Well, if we have a buffer, then that's our parent, if we don't
                    // we will use the parent we saved when we popped the last parent state.
                    $parentKey = !empty($state['buffer']) ?
                        $this->prefixParentKeys($state['buffer'], $state['parent']) : $this->flattenKeys($state['prevParent']);

                    if (preg_match('/^:(\w+)\(([^)]+)\)/', substr($str, $state['pos']), $match)) {
                        // We have a match
                        list($param, $key, $val) = $match;
                        $len = \strlen($param);

                        // Initialise the parent key in our params associative array
                        if (!isset($state['params'][$parentKey])) {
                            $state['params'][$parentKey] = [];
                        }

                        // Store the param key and value
                        $state['params'][$parentKey][$key] = $val;

                        // Chop our parameter out of the original string
                        $str =
                            substr($str, 0, $state['pos']).
                            substr($str, $state['pos'] + $len);

                        // We need to move the position head back one after the chop
                        // since it will be advanced at the end of the loop
                        $state['pos']--;
                    }
                    break;
                default:
                    // Any other character should just be appended
                    $state['buffer'] .= $state['char'];
                    break;
            }
            $state['pos']++;
        }

        // Finally handle any non-empty buffer
        if (!empty($state['buffer'])) {
            $state['keys'][] = $this->prefixParentKeys($state['buffer'], $state['parent']);
            $state['buffer'] = '';
        }

        return (new Includes())
            ->set($state['keys'])
            ->setParams($state['params']);
    }
110946
public function parse($str)
	{
		if ($this->isQuoteHtml() === true)
		{
			$str = htmlspecialchars($str, ENT_QUOTES);
		}

		foreach ($this->getBbCodes() as $key => $val)
		{
			$str = preg_replace($key, $val, $str);
		}

		return $str;
	}