Jump to content

[SOLVED] Remove HTML whitespace


Michan

Recommended Posts

Hi,

 

I seem to be stuck. I've tried replacing \n and \r, but it doesn't seem to have any effect on the code, which looks something like this:

 

Line 1<br />

Line 2<br />

Line 3

 

How would I fix this with a function so it would display in HTML as the following?

 

Line 1<br />Line 2<br />Line 3

 

Many thanks in advance,

 

- Mi

Link to comment
https://forums.phpfreaks.com/topic/125151-solved-remove-html-whitespace/
Share on other sites

Just use PHP_EOL, as it uses the appropriate End of Line depending on the OS. Also F1Fan, str_replace() takes 3 parameters. :)

 

Thank you very much for this. It tidies it all onto a single line, but converts all of the <, >, ", ', &, etc into their HTML codes. Is there a way to remove the HTML returns without converting all of the HTML codes?

 

Many thanks again!

Ha, yeh just remove the htmlentities(). I just had it there to show that it was putting it all into one line.

 

$str = <<<html
Line 1<br />

Line 2<br />

Line 3
html;

echo "<pre>".$str."</pre>";
echo "<pre>".str_replace(PHP_EOL,"",$str)."</pre>";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.