= mb_strlen($line) || ($commonIndent !== null && $indent >= $commonIndent) ) { continue; } $commonIndent = $indent; if ($commonIndent === 0) { break; } } if ($commonIndent) { for ($i = 1; $i < $linesLength; $i++) { $line = $lines[$i]; $lines[$i] = mb_substr($line, $commonIndent); } } // Remove leading and trailing blank lines. while (count($lines) > 0 && trim($lines[0], " \t") === '') { array_shift($lines); } while (count($lines) > 0 && trim($lines[count($lines) - 1], " \t") === '') { array_pop($lines); } // Return a string of the lines joined with U+000A. return implode("\n", $lines); } private static function leadingWhitespace($str) { $i = 0; while ($i < mb_strlen($str) && ($str[$i] === ' ' || $str[$i] === '\t')) { $i++; } return $i; } }