Should I wrap it all inside <? Php?> Using PHP?
Is there any difference between the following 2?
1 separate php code from html
<html> <body> <?php // php code 1 ... ?> <div> ... </div> <?php // php code 2 ... ?> <div> ... </div> <?php // php code 3 ... ?> </body> </html> 2 everything inside php
<?php echo "<html>"; ehco "<body>"; // php code 1 ... echo "<div> ... </div>"; // php code 2 ... echo "<div> ... </div>"; // php code 3 ... echo "</body>"; echo "</html>"; ?> Which is faster?
Normal use is what you specified in the first form, although in some cases, for example, a helper function to generate <a href="..." ... >link word</a> , you will generate HTML inside PHP code. Or if you have a function that generates a table, or ul with many li printed with data from an array or hashes.
Performance:
Perhaps the second example will be a bit slower because it makes more function calls, and also when the string is inside double quotes, then the interpreter will look for variables to replace and escape sequences, for example. \ n
PHP blocks should also be parsed. It may not matter, your script is precompiled / run on the accelerator.
Formatting:
In the first example, HTML will be generated that is automatically indented. The second example will lead to the creation of code that will be displayed on one line. This is not a problem, as it can be fixed.
Resolution:
Perhaps the first example is more readable. For instance. IDE can highlight HTML syntax and separately for PHP
Others:
A second example is likely to be a preferable choice if the code is in a structure and the markup is extracted into a smaller function (s), subclass, etc.?