surround

@param string       $string
@param string|array $substring

@return  string
426201
public static function surround($string, $substring = ['"', '"'])
    {
        $substring = (array) $substring;

        if (empty($substring[1])) {
            $substring[1] = $substring[0];
        }

        return $substring[0] . $string . $substring[1];
    }
313421
function substringPlacement( $startOffset, $endOffset, $totalStringLength )
    {
        $leftText = false;
        $rightText = false;

        if ( $startOffset > 0 )
            $leftText = true;

        if ( $endOffset < $totalStringLength-1 )
            $rightText = true;

        return array( 'hasTextLeft' => $leftText,
                      'hasTextRight' => $rightText );
    }
1158411
public static function substring($string, $length = 50, $start = 0, $ellipsis = true)
    {
        $newString = trim(mb_substr($string, $start, $length, 'UTF-8'));
        if (mb_strlen($newString) < mb_strlen($string) && $ellipsis) {
            return $newString.'...';
        } //&hellip;

        return $newString;
    }
100254
private function separateSelectString(string $string)
    {
        if (false === strpos($string, '(')) {
            return array_map('trim', explode(',', $string));
        }

        $opened = $closed = 0;
        $cnt = mb_strlen($string);
        $arrayStrings = [];
        $substring = '';

        for ($i = 0; $i < $cnt; $i++) {
            $substring .= $string[$i];
            if ('(' === $string[$i]) {
                $opened++;
            } elseif (')' === $string[$i]) {
                $closed++;
            } elseif (',' === $string[$i] && $opened === $closed) {
                $arrayStrings[] = trim($substring);
            }
        }
        $arrayStrings[] = trim($substring);

        return $arrayStrings;
    }
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);
	}
834852
public function surround($string, $in_place = false)
    {
        $surround = array_map(function ($value) use ($string) {
            return $string . $value . $string;
        }, $this->list);

        if ($in_place) {
            $this->list = $surround;

            return $this;
        }

        return new ItemList($surround);
    }
760827
function _string_shift(&$string, $index = 1)
    {
        $substr = substr($string, 0, $index);
        $string = substr($string, $index);
        return $substr;
    }
543941
private static function removeParenthesis(string $string): string
    {
        if (substr($string, 0, 1) === '[' && substr($string, -1) === ']') {
            return substr($string, 1, strlen($string) - 2);
        }

        return $string;
    }
496622
public static function left(string $string, int $count): string
    {
        return self::substr($string, 0, $count);
    }
613088
public static function substring($string, $startpos, $endpos = -1)
    {
        $len = strlen($string);
        $endpos = (int) (($endpos === -1) ? $len - 1 : $endpos);
        if ($startpos > $len - 1 || $startpos < 0) {
            trigger_error("substring(), Startindex out of bounds must be 0<n<$len", E_USER_ERROR);
        }
        if ($endpos > $len - 1 || $endpos < $startpos) {
            trigger_error("substring(), Endindex out of bounds must be $startpos<n<" . ($len - 1), E_USER_ERROR);
        }
        if ($startpos === $endpos) {
            return (string) $string{$startpos};
        } else {
            $len = $endpos - $startpos;
        }

        return substr($string, $startpos, $len + 1);
    }
924593
public function removeLeft($substring)
    {
        $stringy = static::create($this->str, $this->encoding);

        if ($stringy->startsWith($substring)) {
            $substringLength = \mb_strlen($substring, $stringy->encoding);
            return $stringy->substr($substringLength);
        }

        return $stringy;
    }
733126
protected function doInsertStringBeforePosition(string $string, string $insertStr, int $position): string
    {
        return \substr($string, 0, $position) . $insertStr . \substr($string, $position);
    }
1054896
public static function substring($string, $start = 0, $length = null)
    {
        if (!self::isValid($string)) {
            return false;
        }

        return mb_substr($string, $start, $length);
    }
673932
protected function argumentsContain(array $arguments, $substring)
    {
        foreach ($arguments as $argument) {
            if (stristr($argument, $substring) !== false) {
                return true;
            }
        }

        return false;
    }
138709
private static function doPad(
        $string,
        $left,
        $right,
        $substring,
        $encoding = null
    ) {
        $strLength = Mbstring::strlen($string, $encoding);
        $padLength = Mbstring::strlen($substring, $encoding);
        $paddedLength = $strLength + $left + $right;

        if (!$padLength || $paddedLength <= $strLength) {
            return $string;
        }

        $leftStr = Mbstring::substr(str_repeat($substring, (int) ceil($left / $padLength)), 0, $left, $encoding);
        $rightStr = Mbstring::substr(str_repeat($substring, (int) ceil($right / $padLength)), 0, $right, $encoding);

        return $leftStr . $string . $rightStr;
    }
1174036
public function endsWithIgnoreCase($substring) {
		$substring = mb_strtolower($substring, $this->encoding);
		$substringLength = mb_strlen($substring, $this->encoding);
		$endOfStr = mb_strtolower(mb_substr($this->string, $this->length() - $substringLength, $substringLength, $this->encoding));

		return (string) $substring === $endOfStr;
	}
684991
protected function _obscureString($string)
    {
        $len = strlen($string);
        if ($len > 3) {
            return substr($string, 0, 1) . str_repeat('*', $len - 2) . substr($string, -1);
        }

        return str_repeat('*', $len);
    }