tags:

views:

11

answers:

1

Hi, I have XHTML that has empty (blank) lines:

some_tag

empty line

empty line

empty line

some_tag

I wonder how to get rid of them using PHP str_replace. The result should be some_tag some_tag. What are these blank lines anyways?

A: 
$output = str_replace(array("\n", "\r"), '', $input);

OK, after that everything will be in one line. Hope that's ok. Otherwise you'd have to use regular expressions to get rid only of line breaks which are not within tags.

kschaper
Thanks, I have tried str_replace(array('\n', '\r'), '', $input) but it didn't work. Your code works, thanks.
Jan Kraus
Yes, there are indeed some differences between single and double quotes, see http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.single
kschaper