March 24, 2012

PHP: How to Hide <br /> in Console

Question by Kinz

Okay, so I’ve got a program that converts nl2br, and prints the output to a console window. Though it prints along with the output data, the <br />. I’m fine with it and all, if I can’t remove/hide it without all the output melding together, but I’d rather hide/remove it if possible. Any suggestions are thankfully accepted.

-Example-
What console says:
: Output here!<br />
What I want:
: Output here!

I’ve tried substr($out, 5), trim(), and that’s all I could come up with. All those did was meld the output together.

Answer by ShinTakezou

It’s not totally clear, but I suspect you misuderstood nl2br. As the name suggests, it adds for each “newline” a “br” before, so that in HTML (which treats newlines like spaces in text) you will see actualy the text continuing in the next line. When you print to console, the console interprets usually the newline as a newline and so a new line begins. You do not have to use nl2br if you want to output “it” to console. (See nl2br for details).

Answer by Starx

That’s what nl2br() does, changes new line character n to <br />.

If you want, take those out, you can use str_replace()

str_replace("<br />", "", $output);

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!