Right i will get stright to the point:

In the database "newsStory" I have:

blah news 1 blah news 1 blah news 1 blah news 1 blah news 1 blah news 1 blah news 1 blah news 1 blah news 1 blah news 1 blah news 1 blah news 1 blah news 1 blah news 1 blah news 1 sdsdsd sdfdsfsd d sd df df
sd sdf

s dfsfdf

s dfs s
d
s dsd
fsd
sd
f
sd sdsd
fsd f
sd
fs
df
s
s

When this is output to the browser i get:

blah news 1 blah news 1 blah news 1 blah news 1 blah news 1 blah news 1 blah news 1 blah news 1 blah news 1 blah news 1 blah news 1 blah news 1 blah news 1 blah news 1 blah news 1 sdsdsd sdfdsfsd d sd df df sd sdf s dfsfdf s dfs s d s dsd fsd sd f sd sdsd fsd f sd fs df s s d fsd f sd f s fs df sd sdf sd f sd fsd f dfsdfs sdf s fs df s f sdf sdfsfsd fsd f s sd fs fsdfs

This is causing me some headaches. How can i retain the text format. i have tried searching the forum 🙁

Cheers
Paul

    [man]nl2br()[/man] is your friend. Obviously you didn't search hard enough since this is covered OHHHHH so many times per week (almost immeasurable). Hint... Try searching for the phrase "line breaks" and see how quickly you find it.

      Use the carriage return: \n

      It forces text to next line, the same as <br> in HTML.

        Davy, the problem with that is if Paul has no control of the input. Sure, you can tell an end user to put \n everywhere they want a line break to appear, but there aren't too many people who would want to accomodate that...

          Good you see were i am comming from 🙂

          solution????

          thanks

          sorry forgot to mention the formatted text in the DB has come from a form field textarea.

            I'm reading that page on nl2br but it does the same?

            <?php
            echo nl2br("foo isn't\n bar");
            ?> 

            Does the same as

            echo "foo isn't\n bar";

            Or does the nl2br() function actually take the

            new
            lines

            that are inputted and automatically put the <br /> tags in? What happened to <br>

            BTW what the hell are these <br /> tags anyway? I learned nothing of them from college, books nor online tutorials?

              <br> and <br /> tags HTML markup tags to indicate a line break. The latter is XHTML 1.0 and HTML 4.0 compliant. The <br> still exists, but is deprecated in the XHTML standards, which state that ALL tags (even tags with no closing tags like the <br> tag) need to be closed, so the addition of the slash. For example, <hr> becomes <hr />, <input> becomes <input />.

              The nl2br() function takes the output from the database, and anywhere it detects a line break, inserts one into the output automatically for the HTML to parse it.

              In the example you originally gave, it takes your data, and reinserts the line breaks for you. Without it, all of your line breaks go away, like you showed...

              Apply the nl2br() function to your database output, and see how that works out for you.

                Works now 🙂 🙂

                thanks guys

                $newsStory = nl2br($news['newsStory']);
                
                  Write a Reply...