The line break can be removed from string by using str_replace() function. The str_replace() function is an inbuilt function in PHP which is used to replace all the occurrences of the search string or array of search strings by replacement string or array of replacement strings in the given string or array respectively.
str_replace ( $searchVal, $replaceVal, $subjectVal, $count )
Return Type: This function returns a new string or array based on the $subjectVal parameter with replaced values.
Example: After replacing the <br> tag, the new string is taken in the variable text.
Using preg_replace() function: The preg_replace() function is an inbuilt function in PHP which is used to perform a regular expression for search and replace the content.
preg_replace( $pattern, $replacement, $subject, $limit, $count )
Return Value: This function returns an array if the subject parameter is an array, or a string otherwise.
Example: This example use preg_replace() function to remove line break.
- How to prevent line breaks in the list of items using CSS?
- How to add line breaks to an HTML textarea?
- How to Read a File Line by Line to String in Golang?
- How to read a file line by line using node.js ?
- How to put string in array, split by new line in PHP ?
- How to remove the first character of string in PHP?
- Remove new lines from string in PHP
- How to remove extension from string in PHP?
- How to remove portion of a string after a certain character in PHP?
- How to remove all non-printable characters in a string in PHP?
- How to remove all leading zeros in a string in PHP ?
- How to remove control characters from PHP string ?
- How to remove all white spaces from a string in PHP ?
- How to Remove Special Character from String in PHP ?
- How to remove white spaces only beginning/end of a string using PHP ?
- PHP | ImagickDraw line() Function
- PHP | GmagickDraw line() Function
- How to execute PHP code using command line ?
- PHP | Remove duplicate elements from Array
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.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.