Jump to content

making page source readable in php


guilmet

Recommended Posts

I'd like to recommend not echo'ing the source tags, only echo the values you need in the code.  There are a few reasons for this.  1) a good IDE has syntax highlighting for the html code. 2) a good IDE can help you find errors in your HTML code, such as unclosed tags, and can't do this if you are echoing the tags. 3) It is a lot easier for the developer to read the HTML code in the server side source, even without syntax highlighting, when the HTML code is separated from the PHP. 4) It makes it a lot easier to change up the layout of the page later on. 

 

If you put a whole bunch of \t and \n formatting tags into your code, it is probably going to become an eyesore to read and debug.

 

For example:

 

<?
foreach($array as $key=>$val) {
  echo '<tr><td>The value of '.$key.' is: </td><td>'.$val.'</td></tr>';
}

/*   becomes easier to read:   */

foreach($array as $key=>$val) {
  ?>
  <tr><td>The value of <?php echo $key; ?> is: </td><td><?php echo $val; ?></td></tr>;
<? } ?>

 

Archived

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

×
×
  • Create New...

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.