In this tutorial, we are going to learn about how to remove the new line character from a string in PHP.
To remove the new line character from a string, we can use the
str_replace() function by passing
\n regex as an argument in PHP.
Here is an example, that removes the new line character from the following string:
$greet = " Hello Google "; $string = str_replace("\n", " ", $greet); echo $greet;