Twig/TokenParser/ExampleTokenParser.php
private function removeExtraIndentation($string)
    {
        $lines = \preg_split('/\\n|\\r\\n?/', $string);

        // determine indentation length
        $indentLen = null;
        for ($i = 0; isset($lines[$i]); ++$i) {
            if ('' !== \trim($lines[$i])) {
                \preg_match('/^\\s*/', $lines[$i], $match);
                $indentLen = \strlen($match[0]);
                break;
            }
        }

        if (null !== $indentLen) {
            // cut each line
            $out = '';
            for (; isset($lines[$i]); ++$i) {
                if (\substr($lines[$i], 0, $indentLen) === $match[0]) {
                    $out .= \substr($lines[$i], $indentLen);
                } else {
                    $out .= $lines[$i];
                }
                $out .= "\n";
            }

            return $out;
        }

        return $string;
    }
private function removeExtraIndentation($string)
    {
        $lines = \preg_split('/\\n|\\r\\n?/', $string);

        // determine indentation length
        $indentLen = null;
        for ($i = 0; isset($lines[$i]); ++$i) {
            if ('' !== \trim($lines[$i])) {
                \preg_match('/^\\s*/', $lines[$i], $match);
                $indentLen = \strlen($match[0]);
                break;
            }
        }

        if (null !== $indentLen) {
            // cut each line
            $out = '';
            for (; isset($lines[$i]); ++$i) {
                if (\substr($lines[$i], 0, $indentLen) === $match[0]) {
                    $out .= \substr($lines[$i], $indentLen);
                } else {
                    $out .= $lines[$i];
                }
                $out .= "\n";
            }

            return $out;
        }

        return $string;
    }
Remove extra indentation from a string.

@param string $string

@return string