...

View Full Version : echo nl2br??



kred
10-07-2004, 10:04 PM
I'm trying to use "echo nl2br" to seperate new lines from a DB driven description for a job, but when I added "nl2br" to "echo" it puts a huge space at the top of the page, if I remove "nl2br" from "echo" the page appears correctly,, I not explaining it very well so I'll just show an example:

with "nl2br" to "echo" the page appears like this:

--title image


{
huge space added
}



--then copy

without "nl2br" to "echo" the page appears like this:

--title image
--then copy

no huge space being added. appears correctly

why is that? and how can I work around it? or fix it

Thanks for any direction
Ken

sad69
10-07-2004, 10:28 PM
I think it would be helpful to see some code.

It might also be that the text that you are passing to nl2br() has a bunch of new line characters in it? Upon executing it, take a look at the HTML source code in your browser and see if you see a bunch of <br/>'s in the area you're describing. If you do, chances are that the text has lots of new line characters in it and that's where the problem lies.

But, it's hard to debug without seeing the code...

Sadiq.

firepages
10-08-2004, 04:04 AM
its probably as Sadiq says so maybe try
<?echo nl2br(trim($string));?>

mrjamin
10-08-2004, 02:52 PM
why is that? and how can I work around it? or fix it

looks like extra whitespace at the beginning of the var, try this:



<?php
// trim -- Strip whitespace from the beginning and end of a string
// http://www.php.net/trim
echo nl2br(trim($foo));
?>


edit: beat me to it!
might be worth sticking in a regexp to replace more than 2 occurances of whitespace with just 2:


$foo = eregi_replace("((\r)?\n){3,}","\r\n\r\n",$foo);


that should do it, haven't tested it so don't blame me if it doesn't work



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum