I'm using php with mysql. I have a section on my site where a member may submit info of themselves in a text box. When this info is called up to be viewed there is no structure to the paragraphs. There are no indents or skipped lines etc.. It just prints staight from the database on one line utill the page ends, then goes to the next line without indents, skipped lines etc. How can I call up this info where the paragraph will be formatted the same as it is when it is submitted. Thanks in advance, Owen The Samoan

    What you are asking can not be achieved without the user entering the data in an html format to begin with. It is what it is. There is no formatiing of plain text, How are you going to enforce that users input html tags (that actually work) in the textarea? Unless you build a method of doing this then basically that is what you will get. If the data is not formatted to begin with it will remain that way.

      I have called up this information in a text field on a page and it is formatted in the same way that it was submitted. I'm guessing that there must be a way of doing this without the text area.

        The only function I can think of right now that might help is nl2br() but a <p> tag and the closing </p> tag is not really helpful...like I said you need the user to enter that into the textarea and then process it further on another page, possibly also using javascript but not depending on the user as in a page with the actual form.

          As of now the members are submitting their info into a form and they are not adding any html. I look in the database and I see no html but when I call up the info from the database inside a text are like this, everything is formatted perfectly and exactly as it was submitted.

                   <textarea rows="15" name="message" cols="60">

          <?
          echo "$message";
          ?>

          </textarea>

            Try replacing \n with <br> on $message before outputting it (not in a text box). Any line breaks created during input will be translated. If it doesn't work try replacing \r\n with <br>.

            $formatted_message = str_replace("\n","<br>", $message);
            echo $formatted_message;
            

              Use [man]nl2br/manand see if that gives you the desired output.

                I tried $formatted_message = str_replace("\n","<br>", $message);
                echo $formatted_message;

                Works perfectly. Thanks EVERYONE!

                  Also, if spaces aren't being handled properly, you might replace them with the HTML entity &nbsp; like so:

                  $formatted_message = str_replace(' ', '&nbsp;', nl2br($message));

                  The above code snippet accomplishes both the line break issue as well as the spacing issue.

                  Don't forget to mark this thread resolved, too.

                    Write a Reply...