Jump to content

Archived

This topic is now archived and is closed to further replies.

xfezz

quick question about generated html source code

Recommended Posts

the html source code generated from this block of code is one big long line of html code. (seems to scroll like 10 pages across, one div tag after another with the output of the database)

[code]    $SQL = "SELECT * FROM articles ORDER BY id DESC";
    $result = mysql_query($SQL);
      while ($db_field = mysql_fetch_array($result)) {
$now_format = $db_field['article_date'];
$new_format = date('F d, Y',strtotime($now_format)); // transform
                echo "<div id=\"article_date\">". $new_format ."</div>";  // prints out: date in following format October 20, 2006
echo "<div id=\"article_chk\">"."<input type=\"checkbox\" name=\"del_select[]\" value=\"$db_field[id]\" />"."</div>"."<br>";
$db_field['message']=nl2br($db_field['message']);
                echo "<div id=\"article_body\">" .$db_field['message']  ."</div>";
}[/code]

Is there a way to have  the output separated it when viewing the html source code? so it looks nice and neat?

Share this post


Link to post
Share on other sites
Adding a /n will give you a line break:

echo "<div id=\"article_body\">" .$db_field['message']  ."</div>/n";

Share this post


Link to post
Share on other sites
ok ty i got the line break. its \n btw not /n. another quick question. I have seen some sites that have the html source code lines indented. obviously it was generated code. anyone know how they did that?

Share this post


Link to post
Share on other sites
Or you could simply include the spaces/tabs within the echo statements. This:

[code]<?php
echo "<table>\n";
echo "    <tr>\n";
echo "        <td>Data1</td>\n";
echo "        <td>Data2</td>\n";
echo "        <td>Data3</td>\n";
echo "    </tr>\n";
echo "</table>\n";
?>[/code]

Will output this:
[code]<table>
    <tr>
        <td>Data1</td>
        <td>Data2</td>
        <td>Data3</td>
    </tr>
</table>[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.