Remove newline character from a string using PHP regex

$string = str_replace(PHP_EOL, '', $string);

or

$string = str_replace(array("\n","\r"), '', $string);

$string = str_replace("\n", "", $string);
$string = str_replace("\r", "", $string);

To remove several new lines it's recommended to use a regular expression:

$my_string = trim(preg_replace('/\s\s+/', ' ', $my_string));

Better to use,

$string = str_replace(array("\n","\r\n","\r"), '', $string).

Because some line breaks remains as it is from textarea input.