SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Thread: PHP Code Wrap

  1. #1
    SitePoint Addict Eric1776's Avatar
    Join Date
    May 2002
    Location
    Atlanta, GA
    Posts
    227
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP Code Wrap

    Why when I write print statements in php does the code when I view source stay on one line.

    For example I write:
    PHP Code:
    print "Line 1<br>";
    print 
    "Line 2";
    print 
    "Line 3"
    Once I upload the file and I view the source, the entire thing is on one line. How do I have it so each statement is on its own line.

    PHP Code:
    Line 1<br>Line 2Line 3 
    I was using php to write some html elements in the page and I noticed this.

    Thanks

  2. #2
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to send a newline charceter for every line you want in the source code:

    PHP Code:
    <?php

        
    echo "Something\n here\n";

    ?>
    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  3. #3
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    print "Line 1<br>\n";
    print "Line 2\n";
    print "Line 3\n";
    Just add newlines '\n'.

    EDIT: got beat - if only everythingbuffy was done with the same alacrity

  4. #4
    SitePoint Addict Eric1776's Avatar
    Join Date
    May 2002
    Location
    Atlanta, GA
    Posts
    227
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. For some reason I knew that, but just didn't think of it.

  5. #5
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually, you could do this too:
    PHP Code:
    <?php
    echo'
    <html>
       <head>
       <title>Title of Page</title>
       </head>
       <body>
          <p>A paragraph</p>
       </body>
    </html>'
    ;
    ?>
    The inherent problem here is that you cannot parse variables in single quotes, but if you have a long block of html items you want to parse that does not include variables, you could do this.

    Aaron
    Aaron Brazell
    Technosailor



  6. #6
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually, if you want to do something like that (have a large block of HTML that you want to print that does not include variables), it would be clearer to simply escape out of PHP.

    Just a thought

    anticipating your reply, Aaron - 2! EDIT: actually, if you do reply, this will be 6000, so you may want to reconsider

  7. #7
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Already reached 6000.

    But yes you are correct. But since the issue was line breaks when printing from within PHP then this is my response.
    Aaron Brazell
    Technosailor



  8. #8
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    or you could do:

    PHP Code:
    $var "<html>
      <head>
        <title>
    $pagetitle</title>
      </head>
      <body>
        
    $content
      </body>
    </html>"

    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  9. #9
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or you could just do this....

    BOOOOMMMMM..... LoL


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •