A Quick PHP Question...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Big John
    Confirmed User
    • May 2006
    • 470

    #1

    A Quick PHP Question...

    I need to combine some strings and send them to a page with a multi-line form field in it (hope that makes sense). In itself this is simple and so's the problem...

    I want to insert a line break betweek each bit of data (it's an address field and I want each piece on its own line). How to do it? Obviously being an form field <br \> won't work so what do I use? Is there an escape character?

    for example I want:

    $ addressfield = $ street . (new line) . $ city . (newline) etc

    I figure someone here must know how to do something so simple. It's such a daft thing to not know how to do that finding how is proving impossible.
  • Nookster
    Confirmed IT Professional
    • Nov 2005
    • 3744

    #2
    $addressfield = $street . '\n' . $city . '\n' . $etc;
    The Best Affiliate Software, Ever.

    Comment

    • munki
      Do Fun Shit.
      • Dec 2004
      • 13393

      #3
      I think this is what you are looking for, or at least close.

      http://us2.php.net/manual/en/function.nl2br.php

      I have the simplest tastes. I am always satisfied with the best.” -Oscar Wilde

      Comment

      • boldy
        Macdaddy coder
        • Feb 2002
        • 2806

        #4
        use "\n\r" or "\r"

        not sure.
        MacDaddy Coder.

        Comment

        • Nookster
          Confirmed IT Professional
          • Nov 2005
          • 3744

          #5
          Originally posted by munki
          I think this is what you are looking for, or at least close.

          http://us2.php.net/manual/en/function.nl2br.php
          Actually he's looking to do the opposite. Here's a bit of code I found years ago that does the trick if you need to convert <br> tags to the newline char...
          Code:
          function br2nl($text) {
             $text = str_replace("<br />","",$text);
             $text = str_replace("<br>","",$text);
             return $text;
          }
          The Best Affiliate Software, Ever.

          Comment

          • boldy
            Macdaddy coder
            • Feb 2002
            • 2806

            #6
            a newline char is \r in a multiline textfield like textarea .
            MacDaddy Coder.

            Comment

            • boldy
              Macdaddy coder
              • Feb 2002
              • 2806

              #7
              try this

              $addressfield = $street . "\r" . $city . "\r";
              MacDaddy Coder.

              Comment

              • Big John
                Confirmed User
                • May 2006
                • 470

                #8
                \n wasn't working for some odd reason. Hmmm...thanks for the replies. I'll try combining it with r as suggested

                Comment

                • Big John
                  Confirmed User
                  • May 2006
                  • 470

                  #9
                  That did it - \r

                  Comment

                  • boldy
                    Macdaddy coder
                    • Feb 2002
                    • 2806

                    #10
                    Originally posted by Big John
                    That did it - \r

                    You are welcome
                    MacDaddy Coder.

                    Comment

                    • Big John
                      Confirmed User
                      • May 2006
                      • 470

                      #11
                      Originally posted by boldy
                      a newline char is \r in a multiline textfield like textarea .

                      You'd be amazed how hard it is to find that little bit of info. I found quite a few pages listings various escape characters etc that missed out the /r. Oh well - now I know and won;t forget. Thanks again

                      Comment

                      Working...