quick php question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mkx
    Confirmed User
    • Nov 2003
    • 4001

    #1

    quick php question

    I am using the following code to echo a customers address from a mysql database:

    <?php print $recipient->address_street ?>

    However, in the DB if there are 2 lines in the value, for example:

    123 street
    Apt 1

    and it will echo it like it is in the db with the double lines. How can I make it echo on just one line, preferably with a comma and space:

    123 Street, Apt 1
    Last edited by mkx; 03-26-2014, 12:43 PM.
  • nm_
    Confirmed User
    • May 2011
    • 328

    #2
    the address string probably has a newline in it or something

    123 street
    Apt 1

    is probably really something like 123 street\n\rApt 1, so maybe look into using preg_replace to replace \n or \n\r with ", " (maybe str_replace works for this too??).

    sorry maybe someone who knows php better will chime in with exact code for you ;]

    Comment

    • mkx
      Confirmed User
      • Nov 2003
      • 4001

      #3
      that sounds like it could work, if anyone can provide the code to do that I will give it a try, also a code to end the preg replace since this value is the only exception

      Comment

      • TFCash
        Confirmed User
        • Apr 2001
        • 1738

        #4
        <?php print nl2br($recipient->address_street) ?>

        should do it for you
        TeenFlood.com Online since 1998.

        TFCash KissMeGirl
        VirginRiches MondoBucks

        tim at tfcash.com or submit a ticket at our HelpDesk

        Comment

        • KickAssJesse
          Confirmed User
          • Jul 2008
          • 942

          #5
          looks like you may need to update your function

          Contact - email: jesse~AT~atkcash~DOT~com - Skype: kickassjesse - ICQ: 386185547
          ATK Cash $$$

          Comment

          • TFCash
            Confirmed User
            • Apr 2001
            • 1738

            #6
            Originally posted by KickAssJesse
            looks like you may need to update your function
            Sorry went back and re-read it, I thought it was printing on one line, and he wanted it to print on both

            <?php print str_replace('\\r\\n','', $recipient->address_street) ?>

            Got to stop pulling these all nighters!
            Last edited by TFCash; 03-26-2014, 02:20 PM.
            TeenFlood.com Online since 1998.

            TFCash KissMeGirl
            VirginRiches MondoBucks

            tim at tfcash.com or submit a ticket at our HelpDesk

            Comment

            • mkx
              Confirmed User
              • Nov 2003
              • 4001

              #7
              hmm the code seems like it would work but isn't make any difference, still echoing with the new line

              Comment

              • mkx
                Confirmed User
                • Nov 2003
                • 4001

                #8
                got it working with this thanks a bunch!

                <?php print str_replace("\n",', ', $recipient->address_street) ?>

                Comment

                • TFCash
                  Confirmed User
                  • Apr 2001
                  • 1738

                  #9
                  Originally posted by mkx
                  hmm the code seems like it would work but isn't make any difference, still echoing with the new line

                  Can you look and see how it is listed in your database ?? Sometimes it's just a \n so then you'd use

                  <?php print str_replace('\\n','', $recipient->address_street) ?>
                  TeenFlood.com Online since 1998.

                  TFCash KissMeGirl
                  VirginRiches MondoBucks

                  tim at tfcash.com or submit a ticket at our HelpDesk

                  Comment

                  • TFCash
                    Confirmed User
                    • Apr 2001
                    • 1738

                    #10
                    Originally posted by mkx
                    got it working with this thanks a bunch!

                    <?php print str_replace("\n",', ', $recipient->address_street) ?>
                    Glad to hear it
                    TeenFlood.com Online since 1998.

                    TFCash KissMeGirl
                    VirginRiches MondoBucks

                    tim at tfcash.com or submit a ticket at our HelpDesk

                    Comment

                    Working...