You replace the actual sequence of newline strings in $input literal character sequence \n (backslash + n) - not a new line. They must be converted back to new lines when reading from the database. Although I suspect that you intend to store these actual strings in the database and use a double-quoted string instead ...
$input = preg_replace('/(\n)+/m', "\n", $input);
Notice that I replaced the first line delimiters with single quotes and the second double-quoted string. \n is a special sequence in a regular expression to indicate a new line (ASCII 10), but it is also a character escape code in PHP indicating the same thing: conflicts can sometimes occur.
source share