quick simple php question

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

    #1

    quick simple php question

    Say that I have some data in my sql database that reads

    "hello how
    are you"

    How do I make it echo on the same line so it displays?

    "Hello how are you"

    Here is my current code to echo it =

    <?php print $hi->hello ?>
  • woj
    <&(©¿©)&>
    • Jul 2002
    • 47882

    #2
    obviously remove new line characters...
    Custom Software Development, email: woj#at#wojfun#.#com to discuss details or skype: wojl2000 or gchat: wojfun or telegram: wojl2000
    Affiliate program tools: Hosted Galleries Manager Banner Manager Video Manager
    Wordpress Affiliate Plugin Pic/Movie of the Day Fansign Generator Zip Manager

    Comment

    • mkx
      Confirmed User
      • Nov 2003
      • 4001

      #3
      howdy woj, im extremely new to php, tried googling it but was a bit confusing. can anyone tell me what I should replace this with? I can't modify the db at all

      <?php print $hi->hello ?>

      Comment

      • HomerSimpson
        Too lazy to set a custom title
        • Sep 2005
        • 13826

        #4
        you need to remove new lines (or <br> tags) from that string

        new lines
        $x = str_replace(array("\r\n","\r"),"",$x);

        tags (will strip all)
        $x = strip_tags($x);

        and then echo it
        Make a bank with Chaturbate - the best selling webcam program
        Ads that can't be block with AdBlockers !!! /// Best paying popup program (Bitcoin payouts) !!!

        PHP, MySql, Smarty, CodeIgniter, Laravel, WordPress, NATS... fixing stuff, server migrations & optimizations... My ICQ: 27429884 | Email:

        Comment

        • mkx
          Confirmed User
          • Nov 2003
          • 4001

          #5
          sorry im still a bit confused, tried this with no luck =

          <?php
          $x = str_replace(array("\r\n","\r"),"",$x);
          $x = strip_tags($hi->hello);
          print $x ?>

          Comment

          • lezinterracial
            Confirmed User
            • Jul 2012
            • 3117

            #6
            Are you just wanting to populate a variable and echo to the screen?

            <?php
            $x = "hello";
            echo $x
            ?>
            Live Sex Shows

            Comment

            • mkx
              Confirmed User
              • Nov 2003
              • 4001

              #7
              No i am trying to echo $hi->hello on one line

              $hi->hello =

              "hello how
              are you

              Comment

              • Dankasaur
                So Fucking Fossilized
                • Sep 2011
                • 1432

                #8
                Originally posted by mkx
                sorry im still a bit confused, tried this with no luck =

                <?php
                $x = str_replace(array("\r\n","\r"),"",$x);
                $x = strip_tags($hi->hello);
                print $x ?>
                Code:
                <?php 
                $x = str_replace(array("\r\n","\r"),"",$hi->hello);
                $x = strip_tags($x);
                print $x ?>

                Comment

                • helterskelter808
                  So Fucking Banned
                  • Sep 2010
                  • 3405

                  #9
                  Originally posted by mkx
                  sorry im still a bit confused, tried this with no luck =

                  <?php
                  $x = str_replace(array("\r\n","\r"),"",$x);
                  $x = strip_tags($hi->hello);
                  print $x ?>
                  Why would that work? What is $x? And what tags are you stripping? Try this:

                  Code:
                  <?php 
                  $hi->hello = "hello how
                  are you";
                  $one_line = trim(preg_replace('/\s+/', ' ', $hi->hello));
                  print $one_line; 
                  ?>

                  Comment

                  • Colmike9
                    (>^_^)b
                    • Dec 2011
                    • 7230

                    #10
                    Would PHP trim work?

                    echo trim($hi,"/n");
                    Join the BEST cam affiliate program on the internet!
                    I've referred over $1.7mil in spending this past year, you should join in.
                    I make a lot more money in the medical field in a lab now, fuck you guys. Don't ask me to come back, but do join Chaturbate in my sig, it still makes bank without me touching shit for years..

                    Comment

                    • sarettah
                      see you later, I'm gone
                      • Oct 2002
                      • 14297

                      #11
                      never mind... Next time I will read the thread first ;p
                      Last edited by sarettah; 05-15-2013, 02:45 PM.
                      All cookies cleared!

                      Comment

                      • helterskelter808
                        So Fucking Banned
                        • Sep 2010
                        • 3405

                        #12
                        Trim is for stripping at the beginning and end of a string.

                        Comment

                        • Colmike9
                          (>^_^)b
                          • Dec 2011
                          • 7230

                          #13
                          Originally posted by helterskelter808
                          Trim is for stripping at the beginning and end of a string.
                          Oh. Is there a simpler one line way to do it like trim, but for the entire string, or was the solution already posted above?
                          Join the BEST cam affiliate program on the internet!
                          I've referred over $1.7mil in spending this past year, you should join in.
                          I make a lot more money in the medical field in a lab now, fuck you guys. Don't ask me to come back, but do join Chaturbate in my sig, it still makes bank without me touching shit for years..

                          Comment

                          • sarettah
                            see you later, I'm gone
                            • Oct 2002
                            • 14297

                            #14
                            Originally posted by Colmike7
                            Oh. Is there a simpler one line way to do it like trim, but for the entire string, or was the solution already posted above?
                            replace is the easiest way. However, in this case it would seem to me that there is some disagreement on what needs to be replaced. The OP says the phrase comes out on 2 lines. If it is an html presentation that would indicate that there is a <br> in the phrase. If it is a text presentation that would indicate that there is a carriage return/linefeed in the phrase.

                            If he needs to get rid of a <br> then strip_tags does that or you could include it in a replace. If he needs to get rid of a carriage return/linefeed then the replace can do that. Since we don't know exactly which needs to be done then a solution like dankasaur's that covers both possibilities will work.

                            A one line solution would be like

                            <?php print str_replace(array("\r\n","\r","<br>")," ",$hi->hello); ?>

                            .
                            Last edited by sarettah; 05-15-2013, 03:12 PM.
                            All cookies cleared!

                            Comment

                            • helterskelter808
                              So Fucking Banned
                              • Sep 2010
                              • 3405

                              #15
                              Originally posted by Colmike7
                              Oh. Is there a simpler one line way to do it like trim, but for the entire string, or was the solution already posted above?
                              The code works in the example I gave, but I can't say if it would work in every situation.

                              Comment

                              • Dankasaur
                                So Fucking Fossilized
                                • Sep 2011
                                • 1432

                                #16
                                Originally posted by sarettah
                                replace is the easiest way. However, in this case it would seem to me that there is some disagreement on what needs to be replaced. The OP says the phrase comes out on 2 lines. If it is an html presentation that would indicate that there is a <br> in the phrase. If it is a text presentation that would indicate that there is a carriage return/linefeed in the phrase.

                                If he needs to get rid of a <br> then strip_tags does that or you could include it in a replace. If he needs to get rid of a carriage return/linefeed then the replace can do that. Since we don't know exactly which needs to be done then a solution like dankasaur's that covers both possibilities will work.

                                A one line solution would be like

                                <?php print str_replace(array("\r\n","\r","<br>")," ",$hi->hello); ?>

                                .
                                Bingo.

                                Comment

                                • sarettah
                                  see you later, I'm gone
                                  • Oct 2002
                                  • 14297

                                  #17
                                  Just an add on.

                                  I was assuming that it was a <br> in there. It could be all sorts of html code that is invisble to the eye (hidden divs, etc) so probably to make sure all possible tags are covered then a better one line solution might be

                                  <?php print strip_tags(str_replace(array("\r\n","\r")," ",$hi->hello)); ?>

                                  And I tend not to use \r\n so my way would probably be (actually my way would be to change it in the db but the OP says he does not have that access, so)

                                  <?php print strip_tags(str_replace(array(chr(10),chr(13))," ",$hi->hello)); ?> which is basically the same thing just different.

                                  The OP needs to look under the sheets (view source) and see exactly what is in the output that is causing the line break in order to derive the best solution.

                                  .
                                  Last edited by sarettah; 05-15-2013, 03:44 PM.
                                  All cookies cleared!

                                  Comment

                                  • woj
                                    <&(©¿©)&>
                                    • Jul 2002
                                    • 47882

                                    #18
                                    mkx,
                                    just hit me up on icq: 33375924 and I'll hook you up...

                                    before one line of code question turns into a 3 page thread...
                                    Custom Software Development, email: woj#at#wojfun#.#com to discuss details or skype: wojl2000 or gchat: wojfun or telegram: wojl2000
                                    Affiliate program tools: Hosted Galleries Manager Banner Manager Video Manager
                                    Wordpress Affiliate Plugin Pic/Movie of the Day Fansign Generator Zip Manager

                                    Comment

                                    • sarettah
                                      see you later, I'm gone
                                      • Oct 2002
                                      • 14297

                                      #19
                                      Originally posted by woj
                                      mkx,
                                      just hit me up on icq: 33375924 and I'll hook you up...

                                      before one line of code question turns into a 3 page thread...
                                      Ah cmon WOJ we are only on post 19.


                                      .
                                      All cookies cleared!

                                      Comment

                                      • Dankasaur
                                        So Fucking Fossilized
                                        • Sep 2011
                                        • 1432

                                        #20
                                        Originally posted by woj
                                        mkx,
                                        just hit me up on icq: 33375924 and I'll hook you up...

                                        before one line of code question turns into a 3 page thread...
                                        Not to mention that if he goes off privately with you instead of collectively being helped, what if someone else runs into this problem? Nothing like finding a similar problem thread and then being disappointed because nobody posted the fix.

                                        Comment

                                        Working...