SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: a silly one?

  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    a silly one?

    this is probably a silly question, but: when using php and (x)html, and all the inevitable "echo" statements, the (x)html rendered by php isn't indented or layed out properly or nicely when i click view source on my browser.

    Now, i know this really doesn't matter...just wondered what other's thoughts were on keeping php rendered html tidy...do you just output html from php all "willy-nilly", or do you try your best to ensure the output is properly layed out?

    i guess this extends to: what's your favourite / the best way to echo large html blocks in php?

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Personally, I don't give a damn. You could add \t's to your strings if you wanna indent it.
    Saul

  3. #3
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I pay more attention to the format of my PHP than of the HTML produced from it.
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,998
    Mentioned
    186 Post(s)
    Tagged
    2 Thread(s)

    echo and viewsource

    If you
    echo "<tag/>";
    echo "<tag/>";
    echo "<tag/>"; etc. etc.
    viewsource will show <tag/><tag/><tag/> ad infinitum
    As said, you can indent with \t and you can add line breaks with \r \n
    echo "<tag/>\r\n";
    echo "\t<tag/>\r\n";
    echo "<tag/>\r\n";
    But if you want to be easy on yourself try heredoc syntax
    PHP Code:
    $out_html =  <<< EOH
    <tag/>
         <tag/>
    <tag/>
    EOH;

    echo 
    $out_html

  5. #5
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The trouble with heredoc is what if you want to echo html in this example?
    PHP Code:
    function print()
    {
        if (
    true) {
            if (
    true) {
                
    $out_html =  <<< EOH
    <tag>
          <tag/>
    </tag>
    EOH;
             }
        }
        echo 
    $out_html;

    now, my html mite be neatly layed out, but my php isn't. If i indent the EOH block html to match the php indenting, then the html becomes inproperly indented.
    That's it!! i've had enough. I quit! this problem is just too much for me to bear

  6. #6
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by fluxman View Post
    i guess this extends to: what's your favourite / the best way to echo large html blocks in php?
    Sorry, I missed this the first time around.

    If youve got a lot of HTML to get through just pop out of PHP mode and back into HTML, then when you need to use PHP pop back in

    PHP Code:
    <?php
    // php here
    ?>
    <!-- Bulk HTML code -->
    <?php
    // more php
    ?>
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming


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
  •