Forum Moderators: coopster

Message Too Old, No Replies

Formatting HTML output

         

ramoneguru

11:05 pm on Oct 31, 2006 (gmt 0)

10+ Year Member



So I'm working with tables and have this:

echo '<table border = "1">' . "\n";
echo '<tr>' . "\n";
echo '<td> row one, cell one <td>' . "\n";
echo '<td> row one, cell two <td>' . "\n";
echo '</tr>' . "\n";

Is there a more simple way to format the html so it comes out on separate lines or is the format I have now probably the best route?
--Nick

jatar_k

11:15 pm on Oct 31, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



that's probably the best route

alternate format

echo '<table border = "1">',"\n";
echo '<tr>',"\n";
echo '<td> row one, cell one <td>',"\n";
echo '<td> row one, cell two <td>',"\n";
echo '</tr>',"\n";

or you could use double quotes for anything that doesn't include double quotes

echo '<table border = "1">',"\n";
echo "<tr>\n";
echo "<td> row one, cell one <td>\n";
echo "<td> row one, cell two <td>\n";
echo "</tr>\n";

doesn't really matter

ramoneguru

11:22 pm on Oct 31, 2006 (gmt 0)

10+ Year Member



Cool, thanks.
--Nick

pixeltierra

7:18 pm on Nov 1, 2006 (gmt 0)

10+ Year Member



There are two other ways.
1) HERE DOC SYNTAX

echo <<<END
<table>
<tr>
<td>$yourVar</td>
</tr>
</table>
END;

and I use this a lot:

2) Turning php on and off

<?php
foreach ($thing as $thingy){
?>//turn off php
<td>
<div><a href='<?=$url?>'><?=$someting?></a><?=$thing?></div>
</td>
<?php // turn php back on
}

Haven't checked this code obviously, but the ideas are there. Hope it helps.