Remove new lines from string in PHP
Given a multiple line sentence or statement the task is to convert the whole statement in a
single line. See the example below.
Examples:
Input : Hello welcome to geeksforgeeks. Output : Hello welcome to geeksforgeeks. Remove the new line between Hello and geeksforgeeks. Input : I love geeksforgeeks Output : I love geeksforgeeks
The idea is to use str_replace()
<?php $text = "Hello \nwelcome to \ngeeksforgeeks" ; echo $text ; echo "\n" ; $text = str_replace ( "\n" , "" , $text ); echo $text ; ?> |
chevron_right
filter_none
Recommended Posts:
- Remove characters from a numeric string such that string becomes divisible by 8
- How to remove extension from string in PHP?
- How to remove the first character of string in PHP?
- How to remove line breaks from the string in PHP?
- How to remove a character from string in JavaScript ?
- How to remove spaces from a string using JavaScript ?
- How to remove portion of a string after a certain character in PHP?
- How to remove text from a string in JavaScript?
- How to remove all non-printable characters in a string in PHP?
- How to remove all leading zeros in a string in PHP ?
- Program to remove consonants from a String
- How to remove all line breaks from a string using JavaScript?
- Form N-copy string with add, remove and append operations
- Remove characters from string that appears strictly less than K times
- GRE Geometry | Lines and Angles
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.