Just in case this catches anyone else: If your headers string has any leading linebreaks, this function will reject it and return an empty array. If that might apply to your input, sanitise it with ltrim().
Trailing empty lines are tolerated/ignored.
Other quirks I noticed just now:
1. Leading whitespace (" " or "\t") in the *first* line will be included in the header's key name in the returned array. ltrim() will prevent that too.
2. Leading whitespace in any subsequent header (before the key) will cause that line to be appended to the preceding header's value, as though it were a run-on of that header.