Conventions for combining PHP with HTML -


i studying php book. author uses echo output html. @ first thought how supposed done, picked more "advanced" book. author of second book inserted php code between html rather echo whole thing. how done in large web development companies work on large projects? can use either, or 1 more accepted other?

take code example:

<?php //pagination if ($pages > 1) {     //determine current page     $current_page = ($start / $display) + 1;      //print out previous page button     if ($current_page != 1) { ?>         <div class="pages"><strong><a href="view_users.php?s=<?php echo ($start - $display); ?>&amp;p=<?php echo $pages; ?>">&nbsp;&lt;&nbsp;</a></strong></div> <?php     }      //print page numbers     ($i = 1; $i <= $pages; $i++) {         if ($i == $current_page) { ?>          <div class="pages active"><span>&nbsp;<?php echo $i; ?>&nbsp;</span></div> <?php     }     else { ?>         <div class="pages"><strong><a href="view_users.php?s=<?php echo ($display * ($i - 1)); ?>&amp;p=<?php echo $pages; ?>">&nbsp;<?php echo $i; ?>&nbsp;</a></strong></div> <?php         }//end of $i = $current_page conditional     }//end of loop      if ($current_page < $pages) { ?>         <div class="pages"><strong><a href="view_users.php?s=<?php echo ($start + $display); ?>&amp;p=<?php echo $pages; ?>">&nbsp;&gt;&nbsp;</a></strong></div> <?php     } }//end of pagination  include('includes/footer.php');  ?> 

is correct way of doing it, or should use this:

echo '<a href="view_users.php?s=' . ($display * ($i - 1)) .  '&p=' . $pages . '&sort=' . $sort . '">' . $i . '</a> '; 

the reason why i'm asking because find difficult align html when using second technique, , don't want develop bad habits on.

the first method makes code more readable. second method useful when need print little amount of html code. can use short open tags insert php code between html tags. example if need print language parameter of url can this:

<a href="index.php?lang=<?=$lang?>" >a link</a> 

this equal this:

<a href="index.php?lang=<?php echo $lang; ?>" >a link</a> 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c++ - Using OpenSSL in a multi-threaded application -

All overlapping substrings matching a java regex -