Line "Breaks" with html and php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Phocus
    New Member
    • Aug 2001
    • 5

    Line "Breaks" with html and php

    I couldnt think of a better subject for this post, so i tried my best. I also ran a few searches looking for something on this topic but I couldnt find anything.

    I've never been able to get "line breaks" when im using a form to work, for example, if i enter:

    line one blah balh

    line 2 blah blah


    Itll echo like:

    line one blah balh line 2 blah blah

    Is there something i can do through PHP and/or HTML that can get around this? Cuz its been a probolem thats been bugging me whenever i work with forms and sql querys and itll make it simpler than entering <br> tags every time i want to break lines.

    Thanx a bunch!
    ~Mike
  • Mark Hensler
    Senior Member
    • Feb 2001
    • 570

    #2
    If you echo "\n";, you'll have line breaks when you view source.
    PHP Code:
    echo "line one blah balh\n";
    echo 
    "line 2 blah blah\n"

    Comment

    • krs-one
      Senior Member
      • Jun 2001
      • 285

      #3
      or use nl2br

      are you also talking about when you output text to the browser? in that case, a "\n" doesn't work, and you have to use the function nl2br() like so:

      PHP Code:
      $text nl2br($oldtext);
      print 
      $text
      Hope this helps.

      -Vic

      Comment

      • Phocus
        New Member
        • Aug 2001
        • 5

        #4
        EDIT: Ok i wrote this after i saw the first reply, and got the second reply while i was writing it, sorry

        The thing is, im working with forms, so if i do like

        <textarea name='testers' rows='20'></textarea>

        and then submit it to a database, or send it to another page, and like the text area would have

        line 01

        line01


        And if i did echoed $testers

        or if i pulled the row from a database Id get

        line01 line02

        And i wana find out if theres a way to have php or html show the lne breaks, without me havnt to manually insert \n characters or <br> tags
        Last edited by Phocus; Mon 13 Aug '01, 6:29am.

        Comment

        • Mark Hensler
          Senior Member
          • Feb 2001
          • 570

          #5
          Is nl2br() what you were looking for?

          You could also use <pre> or <code> HTML tags.

          You could also throw this at the mySQL server..
          SELECT replace(field_name,"\n","<BR>\n") FROM table_name

          Comment

          • Phocus
            New Member
            • Aug 2001
            • 5

            #6
            WOoO HOOOO!!

            The <pre></pre> tags do just the thing, so i dont have to enter any <br> tags or \n characters.


            WOOHOOO!!

            thanx a bunch

            Comment

            • krs-one
              Senior Member
              • Jun 2001
              • 285

              #7
              i already said that

              in case anyone decided not to read my post, i suggested using the nl2br function.

              that, along with PRE tags are not XHTML standards compliant, while the nl2br function attempts to maintain XHTML standards.

              but, you will not always be able to use PRE tags to get what you want done, so, just to be safe, use nl2br.

              -vic

              Comment

              • Mark Hensler
                Senior Member
                • Feb 2001
                • 570

                #8
                <pre> tags aren't XHTML standard?
                Are the <code> tags?

                Comment

                • Phocus
                  New Member
                  • Aug 2001
                  • 5

                  #9
                  Im sorry, i thought when you were talking about the nl2br() function, it would change the \n characters to <br> tags (nl 2 br, New Line too Break tag i kinda thought it ment) so i didnt try it, cuz i didnt want to have to enter \n characters

                  BUT it worked, and the <pre> tags turned out to not work as i would have hoped, because it woudlnt auto return lines and stuff



                  thank you

                  Comment

                  widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
                  Working...