Reference: This is a self-answered question. It was meant to share the knowledge, Q&A style.
How do I detect the ty
Wouldn't it be easier to just replace everything except new lines using regex?
The dot matches a single character, without caring what that character is. The only exception are newline characters.
With that in mind, we do some magic:
$string = 'some string with new lines';
$newlines = preg_replace('/.*/', '', $string);
// $newlines is now filled with new lines, we only need one
$newline = substr($newlines, 0, 1);
Not sure if we can trust regex to do all this, but I don't have anything to test with.
