Forum Moderators: coopster
echo("<td>$person[address]</td>");
echo("<td>$person[city]</td>");
echo("<td>$person[state]</td>");
echo("<td>$person[zipCode]</td>");
echo("<td>$person[phone]</td>");
The page works and renders just fine. The only problem is the source code; when I view the source, the entire table is put on one looong line.
I've heard that the PHP Tidy extension will clean up outputted PHP rendered HTML, but I can't figure out how to use it. I've found a way to render another page:
$tidy = new tidy("input.html");
$tidy->cleanRepair();
echo $tidy;
But that would require tidying up another page, meaning I'd need to have two separate PHP files for one page. Is there any way to put the tidy statement on the same page rather than tidying some other page?
How can I make it actually clean up my messy table?
Thanks!
To use tidy, you have to use output buffering. If you go to the tidy manual [webmasterworld.com] page and scroll to example #2 (a long way down) you can see how to do it - you'll be surrounding your output, as if all of your output is between <html> and </html> in the example.
To save writing echo lots of times you can also use heredoc's -
echo("<td>$person[address]</td>");
echo("<td>$person[city]</td>");
echo("<td>$person[state]</td>");
echo("<td>$person[zipCode]</td>");
echo("<td>$person[phone]</td>");
// becomes
echo <<<STUFF
<td>$person[address]</td>
<td>$person[city]</td>
<td>$person[state]</td>
<td>$person[zipCode]</td>
<td>$person[phone]</td>
STUFF;
echo <<<END
This uses the "here document" syntax to output
multiple lines with $variable interpolation. Note
that the here document terminator must appear on a
line with just a semicolon. no extra whitespace!
END;