php remove newline – Using The str_replace() function and Remove new lines from string and replace with one empty space. The line break can be removed from string by using str_replace() function.
$user_line = trim(preg_replace('/\s+/', ' ', $user_line));
php remove newline
Remove new lines from string and replace with one empty space
Remove newlines using regex.
$user_line = trim(preg_replace('/\s\s+/', ' ', $user_line));
$text = preg_replace("/\r|\n/", "", $text);
PHP: Remove newlines from text
Example
Remove line breaks with PHP
To remove line breaks using PHP see example:
//Removes all 3 types of line breaks $user_line = str_replace("\r", "", $user_line); $user_line = str_replace("\n", "", $user_line);Complete code to remove newlines (characters) from a string in PHP:
I hope you get an idea about php remove newline.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.