function trimHereDoc($txt)
{
return preg_replace('/^\s+|\s+$/m', '', $txt);
}
^\s+
matches whitespace at the start of a line and \s+$
matches whitespace at the end of a line. The m
flag says to do multi-line replacement so ^
and $
will match on any line of a multi-line string.