Strip new lines in PHP-ThrowExceptions

Exception or error:

I’ve been working with phrases the past couple of days and the only problem I seem to be facing is stripping new lines in the html before printing it.

Anybody have any idea how to remove every new lines from HTML using PHP?

How to solve:
str_replace(array("\r", "\n"), '', $string)

Answer:

the pt2ph8 answer didn’t work for me until I have changed it a little bit as follows:

str_replace(array("\\r", "\\n"), '', $string);

You can see the different results in this demo:

http://phpfiddle.org/lite/code/g5s8-nt3i

Answer:

Why not use regular expression like

$string = trim(preg_replace('/\s+/', ' ', $string));

as proposed here.

Leave a Reply

Your email address will not be published. Required fields are marked *