views:

881

answers:

5
A: 

why not display the results on a <div> perhaps or a <p> ??

lock
Hey lock, that's an option/workaround but I've got some javascript that allows the user to click the results and select all>copy to clipboard so from a usability perspective I'd still like to provide a 'home' for the output.
baselinej70
ehehe i dont want to be pesky but divs allow that function too right?
lock
Oops - does it? I'll have a look right now. Thanks for the tip.
baselinej70
+1  A: 

I think the <br /> tag is what you want in this case. Newline characters like \n and \r don't do anything in HTML - all whitespace, including newlines, is ignored. The <br /> tag is essentially the HTML equivalent - it stands for "break". I don't know too much about PHP specifically, so I don't know why it's putting the <br /> there for you automatically, but that's the correct HTML for what you're describing.

Technically, there are better ways to format your output then using those tags, but that's more of an advanced topic. If you are a bit new to this, like you said, then just get it working this way for now, and then maybe sometime down the road you can learn about proper semantic HTML markup, CSS styling, etc.

Jonathan Schuster
A: 

I believe \n should work. Perhaps you do not have or have an incorrect doctype.

Example: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

If all else, I like lock's answer. You could us a <div> and you could even style it to look similar to a <textarea> (or even better!)

T Pops
I think \n will just put it on a new line in the html but it will not put it on a new line when viewed since blank space is just ignored.
Josh Curren
T Pops - checks out "<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">". Might have to resort to dressing up the DIV as per Lock's suggestion. Thanks!
baselinej70
A: 

I'll preface this by saying I use Blogger not Wordpress but I imagine there are similarities. In Blogger there is a setting to convert line breaks into <br> tags. I guess it's convenient if you're not putting code snippets and the like in (if you're blogging about cats or something) but not so much for programming. I had to turn it off and put in my paragraph tags, etc manually.

Here is one less than ideal solution, which also mentions the issue of Wordpress inserting <br> tags in forms.

cletus
I tried different combinations of the suggested solutions but I think you're on the money, cletus. When I took the code out of wordpress and onto a plain php/html page, it worked.
baselinej70
Thanks to all for your help! :)
baselinej70
A: 

It took some looking, but after some time I was able to pinpoint these two locations (lines 154 & 165 - WP 2.8) in the wp-includes/formatting.php file.

154  $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n"; //<-- before
154  $pee .= trim($tinkle, "\n") . "\n"; //<-- after

165  $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee); // optionally make line breaks <-- before
165  $pee = preg_replace('|(?<!<br />)\s*\n|', "\n", $pee); // optionally make line breaks <-- after

This took care of the paragraph and and break tags in my textarea field.

Seriously? $pee and $tinkle? I hate Wordpress code.
Mike B