Question #6815   Submitted by Answiki on 09/30/2022 at 08:22:28 PM UTC

How to remove carriage returns from a string in PHP?

Answer   Submitted by Answiki on 09/30/2022 at 08:35:10 PM UTC

In PHP, to remove line breaks and carriage returns from a string, one can use the str_replace function:

// Remove new line
$string = str_replace("\n", '', $string);
// Remove carriage returns
$string = str_replace("\r", '', $string);

The operation can be done in a single line:

// Remove new line and carriage return
$string = str_replace(array("\r", "\n"), '', $string); 

See also:



6 events in history
Question by Answiki 09/30/2022 at 08:35:19 PM
How to remove carriage returns from strings in PHP?
Answer by Answiki on 09/30/2022 at 08:35:10 PM

In PHP, to remove line breaks and carriage returns from a string, one can use the str_replace function:

// Remove new line
$string = str_replace("\n", '', $string);
// Remove carriage returns
$string = str_replace("\r", '', $string);

The operation can be done in a single line:

// Remove new line and carriage return
$string = str_replace(array("\r", "\n"), '', $string); 

See also:



Answer by Answiki on 09/30/2022 at 08:34:05 PM

In PHP, to remove line breaks and carriage returns from a string, one can use the str_replace function:

// Remove new line
$string = str_replace("\n", '', $string);
// Remove carriage returns
$string = str_replace("\r", '', $string);


The operation can be done in a single line:

// Remove new line and carriage return
$string = str_replace(array("\r", "\n"), '', $string); 

See also:



Answer by Answiki on 09/30/2022 at 08:28:59 PM

In PHP, to remove line breaks and carriage returns from a string, one can use the str_replace function:

// Remove new line
$string = str_replace("\n", '', $string);
// Remove carriage returns
$string = str_replace("\r", '', $string);


The operation can be done in a single line:

// Remove new line and carriage return
$string = str_replace(array("\r", "\n"), '', $string); 

See also:



Answer by Answiki on 09/30/2022 at 08:25:39 PM

In PHP, to remove line breaks and carriage returns from a string, one can use the str_replace function:

// Remove new line
$string = str_replace("\n", '', $string);
// Remove carriage returns
$string = str_replace("\r", '', $string);


The operation can be done in a single line:

// Remove new line and carriage return
$string = str_replace(array("\r", "\n"), '', $string); 

// Remove new line and carriage return
$string = str_replace("\r", "\n", '', $string); // remove new lines
See also:



Question by Answiki 09/30/2022 at 08:22:28 PM
How to remove carriage returns from a string in PHP?
# ID Query URL Count

Icons proudly provided by Friconix.