Quick PHP Question

Associate
Joined
26 Jun 2003
Posts
1,140
Location
North West
Im writing a class do do some mysql stuff then print out results in a table.

Is there anyway to print the resulting html code out in a well formatted way?

Code:
function test()
{
  $returnThis = "<table>".
                "  <thead>".
                "    <tr>".
                "      <th>Header 1/th>".
                "      <th>Header 2</th>".
                "      <th>Header 2</th>".
                "    </tr>".
                "  </thead>".
                "</table>";
  return $returnThis;
}

echo test();

However the above html prints it all out in one line. I know its no biggy but I like to see nice html code.
 
Haha thats a way i didnt think of. lol Cheers.

However tho, if you use the code like this:

Code:
...
  <body>
    <div id="wrapper">
      <?=$myClass->getTable()?>
    </div>
  </body>
...

Is printed out

Code:
  <body>
    <div id="wrapper">
      <table>
  <thead>
    <tr>
      <th>Header 1</th>
      <th>Header 2</th>
      <th>Header 2</th>
    </tr>
  </thead>
</table>
    </div>
  </body>

As you can see it is tidyier, however only the opening <table> tag is indented properly.

Any way this can be sorted? :D

Sorry im picky :p
 
Indentation is just to keep it readable when you're writing it - if you're using PHP to generate the html, then why worry about how it's indented?

Not really a big reason, I just like to read nicely laid out html when I need to look through the source.
 
Back
Top Bottom