How to remove line breaks from the string in PHP? Last Updated : 01 Apr, 2021 Summarize Suggest changes Share Like Article Like Report 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.Syntax: 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. php <?php // Declare a variable and initialize it // with strings containing <br> tag $text = "Geeks<br>For<br>Geeks"; // Display the string echo $text; echo "\n"; // Use str_replace() function to // remove <br> tag $text = str_replace("<br>", "", $text); // Display the new string echo $text; ?> Output: Geeks For Geeks GeeksForGeeks 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.Syntax: 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. php <?php // Declare a variable and initialize it // with strings containing <br> tag $text = "Geeks<br>For<br>Geeks"; // Display the string echo $text; echo "\n"; // Use preg_replace() function to // remove <br> and \n $text = preg_replace( "/<br>|\n/", "", $text ); // Display the new string echo $text; ?> Output: Geeks For Geeks GeeksForGeeks Advertise with us Next Article How to prepend a string in PHP? P PranchalKatiyar Follow Similar Reads How to remove all white spaces from a string in PHP ? Given a string element containing some spaces and the task is to remove all the spaces from the given string str in PHP. In order to do this task, we have the following methods in PHP:Table of ContentUsing str_replace() MethodUsing str_ireplace() MethodUsing preg_replace() MethodUsing explode() and 4 min read How to remove control characters from PHP string ? Given a string that contains control characters. The task is to remove all control characters from a string. In ASCII, all characters having a value below 32 come under this category. Some of the control characters are given below: S.NO ASCII VALUE Name Symbol 1. 0 null (NUL) "\0" 2. 9 horizontal ta 2 min read PHP Program to Remove Last Character from the String Given a String, the task is to remove the last character from a string in PHP. This operation is common in text processing and manipulation. Examples: Input: str = "Hello Geeks!"Output: Hello GeeksInput: str = "Welcome"Output: WelcomThese are the following approaches: Table of Content Using substr() 2 min read How to prepend a string in PHP? We have given two strings and the task is to prepend a string str1 with another string str2 in PHP. There is no specific function to prepend a string in PHP. To do this task, we have the following operators in PHP:Below are the methods to prepend a string in PHPTable of ContentUsing Concatenation Op 2 min read How to Extract Substring from a String in PHP? Given a String, the task is to extract a substring from a string in PHP. Extracting substrings from a string is a common task in PHP, whether you need to extract a portion of text based on a specific position or find a substring based on a pattern. In this article, we will explore various approaches 3 min read How to Convert Array to String in PHP? In PHP, Arrays are used to store multiple values in a single variable. However, sometimes we need to convert these arrays into strings:To display array data in a readable format.To join array items into a single sentence or list.To use the array data where only strings are accepted.To prepare data f 2 min read Article Tags : Web Technologies PHP PHP Programs Like