leftTrimBlock() function
<?php
/**
* Remove left padding space from all lines,
* while preserving indentation.
*
* @param string $txt
* @returns string trimmed block of text
*/
function leftTrimBlock($txt)
{
$pad = 1024;
preg_replace_callback('/^( *)(?=[^ \n])/m', function ($m) use (&$pad) {
$pad = min($pad, strlen($m[1]));
}, $txt);
return preg_replace("/^ {{$pad}}/m", '', $txt);
}