我一直在想:是不是有一個大的開放和關閉PHP(即模板)受傷?很多PHP標籤的開啓/關閉
澄清:
<html>
<?php echo $test; ?>
<body <?php echo $test2; ?>>
<table>
<?php foreach ($rows as $row): ?>
<tr>
<td><?php echo $row['cell1']; ?></td>
<td><?php echo $row['cell1']; ?></td>
<td><?php echo $row['cell1']; ?></td>
<td><?php echo $row['cell1']; ?></td>
<?php echo $row['added cells']; ?>
</tr>
<?php endforeach; ?>
</table>
<?php echo $someMorePhp; ?>
<div>
<?php /*do some more php stuff */ ?>
</div>
etc etc
etc
或者這將是可取的,即
<html>
<php echo $test.'<body'.$test2; ?>>
<table>
<?php foreach ($rows as $row) {
echo '<tr>
<td>'.$row['cell1'].'</td>
<td>'.$row['cell2'].'</td>
<td>'.$row['cell3'].'</td>
<td>'.$row['cell4'].'</td>
<td>'.$row['cell1'].'</td>
'.$row['added cells'].'
<tr>';
}
</table>
// etc
我知道這可能看起來像一個微型優化等。要清楚我正在尋找一個經驗法則不是一個具體的用例...它會傷害進入和退出PHP引擎在單個腳本運行期間...
可能重複的[PHP回聲vs打開和關閉標記](http://stackoverflow.com/questions/1394478/php-echo-vs-openclose-tag) – Boann
很多''與HTML東西混合是一種痛苦保持。你的第二種情況似乎更好。但是,我更喜歡避免混合HTML和PHP與模板系統,如[RainTPL](http://www.raintpl.com/) – Arthur
糟糕,對不起,在這裏更好的愚弄:http://stackoverflow.com/questions/2437144/opening -closing-tags-performance – Boann