OK, so here's what's ailing me (perhaps you know a thing or two about this): I'm using a textarea to enter paragraphs into a PostgreSQL database and I want them to output looking similar to how they were input. I've been using the nl2br() function to get decent output, but it places a break <br /> not only where the user hit the return key for a new paragraph (which is what I want), but also where there's a new line in a single paragraph (which is exactly what I don't want). Ever come across a problem like that? I basically want to keep the so-called 'hard breaks' (ie return button) and discard the 'soft-breaks' (ie new lines). Thanks for whatever help you can render...

    Yeah ive noticed this recently

    You could try getting rid of the hard returns before calling nl2br

    Mark

      Pardon my ignorance, but how does one get rid of hard returns (or soft ones for that matter)?

        I think that depends on the "wrap" setting you use in your textarea tag.

        Various browsers implemented wrap in different ways, and as far as I know default textarea behaviour in IE is to "soft wrap" the text, meaning the textarea box does not scroll horizontally and the text is broken into chunks that fit into the box without introducing line breaks into the text.

        This would be equivalent to wrap="soft" or no wrap tag at all in IE.

        Hard wrapping is when the browser introduces line breaks into the text at the point where it must be broken to fit into the box. I believe hard wrapping is NS's default in most versions.

        wrap="off" would mean that the box will scroll horizontally as the user types and line breaks would only be inserted when the user hits the enter key.

        The wrap="virtual" and wrap="physical" attributes were implemented by NS but never widely used, so I would say there is no absolute method of insuring your line breaks are implemented correctly on the client side.

        Due to the differences in default browser behaviour, I prefer to keep "soft" wrapping on and then force my line breaks server side.

        Hope this helps.

          David-

          Thanks for the scoop on wrapping and the inherent browser issues. It seems like it is easiest, as you said, to deal with it on the server end. I'll look into that from here. Do you happen to know the difference between a hard and a soft wrap as far as the server is concerned? Is it a matter of \n and \r or is there more to it than that? I suppose it depends on the server. Anyway, I appreciate the time you took to respond. Take care.

          -Jay

            You could do this to get rid of any hard returns

            $string = str_replace("\r","",$string);

            Mark

              It is only a matter of having the \n or \r or a combination of the two.

              I have noticed some inconsistent behaviour when I edit files in notepad versus VI, sometimes notepad seems to replace \n with \n\r.

              I don't know any specifics on it, maybe someone else can expound.

                Carriage returns are specific to the Windows operating system

                Mark

                  Write a Reply...