Preparing array of integers based on comma separated integers in string or single integer in string.

@param string $string list of integers separated by comma character

@return array

@throws InvalidArgumentException If incorrect $list value is given
493016
public static function getIdListFromString($string)
    {
        if (filter_var($string, FILTER_VALIDATE_INT) !== false) {
            return array($string);
        }

        return array_map(
            function ($id) {
                if (false === filter_var($id, FILTER_VALIDATE_INT)) {
                    throw new InvalidArgumentException('String should be a list of Integers');
                }

                return (int) $id;
            },
            explode(',', $string)
        );
    }
179065
public function loadFromString($string)
    {
        $target = array();
        $array = explode(self::SEPARATOR, $string);

        foreach ($array as $index => $value) {
            // Additional check
            if (!empty($value)) {
                // Ensure we have only clean values
                if (strpos(self::SEPARATOR, $value) === false) {
                    array_push($target, $value);
                }
            }
        }

        // Override with modified one
        $this->collection = $target;
    }
1108838
public static function fromString($string)
	{
		$fg      = '';
		$bg      = '';
		$options = array();

		$parts = explode(';', $string);

		foreach ($parts as $part)
		{
			$subParts = explode('=', $part);

			if (\count($subParts) < 2)
			{
				continue;
			}

			switch ($subParts[0])
			{
				case 'fg':
					$fg = $subParts[1];

					break;

				case 'bg':
					$bg = $subParts[1];

					break;

				case 'options':
					$options = explode(',', $subParts[1]);

					break;

				default:
					throw new \RuntimeException('Invalid option');

					break;
			}
		}

		return new self($fg, $bg, $options);
	}
676982
public function parse($string) {
        if (is_array($string)) {
            $string = implode(' ', $string);
        }

        $args = $this->parseString($string);
        $args = $this->unquoteMatches($args);
        $args = $this->normalizeShortOptions($args);

        return $args;
    }
335360
public function parseFormat($string) {
        $groups = [];

        if (preg_match_all("#(?<!\\\\)<[/]?(\w+)([\sa-z0-9=_;,]*)>#", $string, $matches, PREG_SET_ORDER) !== false) {
            $groups = $matches;
        }

        return $groups;
    }
446468
public static function decodeToInteger($string)
    {
        $stringLength = strlen($string);

        $baseLength = strlen(static::$chars);

        $id = 0;

        for($i = 0; $i < $stringLength; $i++){

            $pos = strpos(static::$chars, $string[$i]);

            $id = ($id * $baseLength) + $pos;

        }

        return $id;
    }
271320
public function encode($string)
    {
        // Type validation
        if (is_string($string) === false) {
            throw new InvalidArgumentException('Argument $string must be a string.');
        }

        // If the string is empty, then the encoded string is obviously empty
        if (strlen($string) === 0) {
            return '';
        }

        // Now we need to convert the byte array into an arbitrary-precision decimal
        // We basically do this by performing a base256 to base10 conversion
        $hex = unpack('H*', $string);
        $hex = reset($hex);
        $decimal = gmp_init($hex, 16);

        // This loop now performs base 10 to base 58 conversion
        // The remainder or modulo on each loop becomes a base 58 character
        $output = '';
        while (gmp_cmp($decimal, $this->base) >= 0) {
            list($decimal, $mod) = gmp_div_qr($decimal, $this->base);
            $output .= $this->alphabet[gmp_intval($mod)];
        }

        // If there's still a remainder, append it
        if (gmp_cmp($decimal, 0) > 0) {
            $output .= $this->alphabet[gmp_intval($decimal)];
        }

        // Now we need to reverse the encoded data
        $output = strrev($output);

        // Now we need to add leading zeros
        $bytes = str_split($string);
        foreach ($bytes as $byte) {
            if ($byte === "\x00") {
                $output = $this->alphabet[0] . $output;
                continue;
            }
            break;
        }

        return (string) $output;
    }
425386
private function parseParameters($string) {

		$parameters      = array();
		$arrayParameters = array();
		$arrayOptions    = array();
		$betweenSQuotes  = false;
		$betweenDQuotes  = false;
		$inKey           = true;
		$inValue         = false;
		$inArray         = false;
		$inOption        = false;
		$char            = "";
		$buffer          = "";
		$keyBuffer       = "";
		$arrayKeyBuffer  = "";
		$strLength       = strlen($string);

		for ($i = 0; $i < $strLength; $i++) {

			$previousChar = $char;
			$char = $string[$i];

			if ($inKey && !$betweenDQuotes && !$betweenSQuotes && (($char == "\"") || ($char == "'"))) {
				// if inKey, a quote, and betweenQuotes is false ignore quote, set betweenQuotes to true and empty buffer to kill spaces
				($char == "\"") ? ($betweenDQuotes = true) : ($betweenSQuotes = true);
			} else if ($inKey && (($betweenDQuotes && ($char == "\"")) || ($betweenSQuotes && ($char == "'"))) && ($previousChar == "\\")) {
				// if inKey, a quote, betweenQuotes is true, and previous character is \ add to buffer
				$buffer   .= $char;
			} else if ($inKey && (($betweenDQuotes && ($char == "\"")) || ($betweenSQuotes && ($char == "'")))) {
				// if inKey, a quote, betweenQuotes is true set betweenQuotes to false, save as key buffer, empty buffer set inKey false
				$keyBuffer      = $buffer;
				$buffer         = "";
				$inKey          = false;
				$betweenSQuotes = false;
				$betweenDQuotes = false;
			} else if ($inKey && !$betweenDQuotes && !$betweenSQuotes && ($char == ":")) {
				// if inKey, a colon, betweenQuotes is false, save as key buffer, empty buffer, set inKey false set inValue true
				$keyBuffer = $buffer;
				$buffer    = "";
				$inKey     = false;
				$inValue   = true;
			} else if ($inKey) {
				// if inKey add to buffer
				$buffer   .= $char;
			} else if (!$inKey && !$inValue && ($char == ":")) {
				// if inKey is false, inValue false, and a colon set inValue true
				$inValue   = true;
			} else if ($inValue && !$inArray && !$betweenDQuotes && !$betweenSQuotes && ($char == "[")) {
				// if inValue, outside quotes, and find a bracket set inArray to true and add to array buffer
				$inArray        = true;
				$inValue        = false;
				$arrayKeyBuffer = trim($keyBuffer);
			} else if ($inArray && !$betweenDQuotes && !$betweenSQuotes && ($char == "]")) {
				// if inValue, outside quotes, and find a bracket set inArray to true and add to array buffer
				$inArray                     = false;
				$parameters[$arrayKeyBuffer] = $arrayParameters;
				$arrayParameters = array();
			} else if ($inArray && !$inOption && !$betweenDQuotes && !$betweenSQuotes && ($char == "{")) {
				$inOption = true;
				$inKey    = true;
			} else if ($inArray && $inOption && !$betweenDQuotes && !$betweenSQuotes && ($char == "}")) {
				$inOption = false;
				$inValue  = false;
				$inKey    = false;
				$arrayParameters[] = $arrayOptions;
				$arrayOptions = array();
			} else if ($inValue && !$betweenDQuotes && !$betweenSQuotes && (($char == "\"") || ($char == "'"))) {
				// if inValue, a quote, and betweenQuote is false set betweenQuotes to true and empty buffer to kill spaces
				($char == "\"") ? ($betweenDQuotes = true) : ($betweenSQuotes = true);
			} else if ($inValue && (($betweenDQuotes && ($char == "\"")) || ($betweenSQuotes && ($char == "'"))) && ($previousChar == "\\")) {
				// if inValue, a quote, betweenQuotes is true, and previous character is \ add to buffer
				$buffer   .= $char;
			} else if ($inValue && (($betweenDQuotes && ($char == "\"")) || ($betweenSQuotes && ($char == "'")))) {
				// if inValue, a quote, betweenQuotes is true set betweenQuotes to false, save to parameters array, empty buffer, set inValue false
				$buffer    = str_replace("\\\"","\"",$buffer);
				$buffer    = str_replace('\\\'','\'',$buffer);
				if ($inArray) {
					$arrayOptions[trim($keyBuffer)] = trim($buffer);
				} else {
					$parameters[trim($keyBuffer)] = trim($buffer);
				}
				$buffer         = "";
				$inValue        = false;
				$betweenSQuotes = false;
				$betweenDQuotes = false;
			} else if ($inValue && !$betweenDQuotes && !$betweenSQuotes && ($char == ",")) {
				// if inValue, a comman, betweenQuotes is false, save to parameters array, empty buffer, set inValue false, set inKey true
				if ($inArray) {
					$arrayOptions[trim($keyBuffer)] = trim($buffer);
				} else {
					$parameters[trim($keyBuffer)] = trim($buffer);
				}
				$buffer    = "";
				$inValue   = false;
				$inKey     = true;
			} else if ($inValue && (($i + 1) == $strLength)) {
				// if inValue and end of the string add to buffer, save to parameters array
				$buffer   .= $char;
				if ($inArray) {
					$arrayOptions[trim($keyBuffer)] = trim($buffer);
				} else {
					$parameters[trim($keyBuffer)] = trim($buffer);
				}
			} else if ($inValue) {
				// if inValue add to buffer
				$buffer   .= $char;
			} else if (!$inValue && !$inKey && ($char == ",")) {
				// if inValue is false, inKey false, and a comma set inKey true
				if ($inArray && !$inOption) {
					// don't do anything
				} else {
					$inKey = true;
				}

			}
		}

		return $parameters;

	}
957584
public static function parseString($string)
    {
        $array = preg_split('/[,;\r\n]+/', trim($string, ",;\r\n"));
        if (strpos($string, ':')) {
            $value = [];
            foreach ($array as $val) {
                list($k, $v) = explode(':', $val);
                $value[$k] = $v;
            }
        } else {
            $value = $array;
        }
        
        return $value;
    }
23537
public function loadString(&$string): array
    {
        /** @noinspection CallableParameterUseCaseInTypeContextInspection */
        $string = $this->unwrap($string);
        $this->rawSegments = $string;

        return $this->parse($string);
    }
93983
public static function parseAttributes($string)
	{
		// Initialise variables.
		$attr = array();
		$ret  = array();

		// Let's grab all the key/value pairs using a regular expression
		preg_match_all('/([\w:-]+)[\s]?=[\s]?"([^"]*)"/i', $string, $attr);

		if (is_array($attr))
		{
			$numPairs = count($attr[1]);
			for ($i = 0; $i < $numPairs; $i++)
			{
				$ret[$attr[1][$i]] = $attr[2][$i];
			}
		}

		return $ret;
	}
918698
public static function createFromString($string)
    {
        if (preg_match('/^(?:(.+) )?<(.+)>$/', $string, $vars)) {
            $name  = $vars[1] === '' ? null : $vars[1];
            $email = $vars[2] === '' ? null : $vars[2];
            return new Person($name, $email);
        }

        throw new \InvalidArgumentException(sprintf('Unable to parse Person "%s".', $string));
    }
365243
public function getArrayWhereKeysBeginWith($string)
    {
        if (empty($this->config)) {
            $this->getArray();
        }
        $config = $this->config;

        $thisConfig = array();
        $cleanNameLength = mb_strlen($string);
        $string = mb_strtolower($string);
        foreach ($config as $key => $value) {
            $begin = substr($key, 0, $cleanNameLength);
            if (mb_strtolower($begin) == $string) {
                $thisConfig[$key] = $value;
            }
        }
        return $thisConfig;
    }
233264
public static function parseRgbaString(string $string) : array
    {
        if (!preg_match(self::REGEX_RGBA, $string, $matches)) {
            throw InvalidArgumentException::format(
                    'Invalid rgba string passed to %s: expecting format "rgb(0-255, 0-255, 0-255, 0-1)", "%s" given',
                    __METHOD__, $string
            );
        }

        return [(int)$matches[1], (int)$matches[2], (int)$matches[3], (float)$matches[4]];
    }
1231460
private function stringToNum(string $string) : BigNumber
    {
        $number = new BigNumber(0);
        foreach (str_split(strrev($string)) as $char) {
            $number->multiply($this->alphabetLength)->add(array_search($char, $this->alphabet, false));
        }

        return $number;
    }
474838
public static function validateString($string)
    {
        if (is_string($string) || (is_object($string) && method_exists($string, '__toString'))) {
            return (string) $string;
        }
        throw new \InvalidArgumentException('Expected data must either be a string or stringable');
    }
353896
private function _parseHADocField($string) {
    $separater = '=';
    $pos = strpos($string, $separater);

    if ($pos !== false) {
      $key = substr($string, 0, $pos);
      $value = substr($string, $pos + 1);
      return array($key, $value);
    } else {
      throw new Exception('The are no key and value in the field.');
    }
  }