php remove newline from string

You can remove new line character any where in string using regex preg_replace.preg_replace is function which work on regex to search and replace in string.Regular express is strong part of php.You can also search replace html tags.Here I have used regex string feature to search and replace new line character.

Here is example how you can remove new line anywhere in php

$str = <<<EOD
Example of string\n example string\n example string.\n example string.\n example string.\n example string.\n\n\n\n niks
$str = preg_replace("/\n/", '', $str);