- str_replace: documentation ( source)
- preg_replace: documentation ( source)
<?php
$answer['message'] = "this is a test message. next is emptyline
and here are to empty lines
end.";
print(preg_replace("/^$/ui", "", str_replace(["\n\r", "\n\n", "\r\r","\r\n"], "\n", $answer['message'])));