en
Home About project

Remove line breaks with PHP

If you need to remove line breaks from text with PHP you can use next string function:

  • mixed str_replace(mixed $search, mixed $replace, mixed $subject [, int &$count])

This function returns a string or an array with all occurrences of search in subject replaced with the given replace value..

Line breaks in text are generally represented as:

  • \r\n - on a windows computer
  • \r - on an Apple computer
  • \n - on Linux

To remove line breaks using PHP see example:

    //Removes all 3 types of line breaks
    $string = str_replace("\r", "", $string);
    $string = str_replace("\n", "", $string);