开发者

Php echo vs jsp style

Which is the fastest:

$开发者_开发技巧content = "some html";
<div><?php echo $content?></div>

or

$content = "some html";
<div><?=$content?></div>

?


Doesn't matter.

<?= ... ?> won't work if short_open_tags are disabled and the version of php is older than version 5.4 though (which is unlikely).

But if you want maximum compatibility, use the <?php echo ...; ?> style.


no difference you could possibly ever notice. However, <?= ... ?> may not work across all servers because short tags is a setting that must be enabled. So you should as a best practice stick to <?php...?>


There would be no difference between full and short tags in terms of performance, but I recommend you utilize the full tags in case short tags are disabled. Additionally you can use single quotes '' if you are not echoeing any PHP variables.

Traditional echo statement

<?php echo "Hello World!"; ?>

Faster echo

<?php echo 'Hello World!'; ?>

If using PHP Variables

<?php echo 'Hello ' . $world; ?>

Or using a comma

<?php echo 'Hello ', $world; ?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜