php / html编码风格[关闭]

Variant 1:

<?php
for ($i = 0; $i<10; $i++) {
?>
    <p>some text</p>
<?php
}
?>

Variant 2:

<?php
for ($i = 0; $i < 10; $i++) {
     echo '<p>some text</p>';
}
?>

There is differnce between this coding styles in performance? or this is just a matter of taste?

Taste. There's also a third one, which is considered more readable:

<?php for ($i = 0; $i < 10; $i++) : ?>
    <p>Some Text</p>
<?php endFor; ?>

The first thing is the good coding standard. We should avoid echoing the html inside the php

Good standard

<?php for ($i = 0; $i < 10; $i++) : ?>
    <p>Some Text</p>
<?php endFor; ?>

It is a matter of taste, but I would avoid variant 2.

It is similar to things like indentation: there is no set rule, but this one is, in my opinion, the most readable:

<?php for ($i = 0; $i < 10; $i++) : ?>
<p>Some Text</p>
<?php endFor; ?>

This, I believe, is also what is used the majority of the time because, as Kalai says:

"We should avoid echoing the html inside the php".

If You don't want to escape <?php ?> then You should use print instead of echo. Print function is faster than echo (which is not actualy a function but special syntax).

I suggest you follow Zend coding standards http://framework.zend.com/manual/1.12/en/coding-standard.html