For example:

I have a php file like this:

<?php
 if ($var == true)
 {
   ?>
     <p>Some text here</p>
   <?php
 }
 else
 {
   ?>
     <p>Some different text</p>
   <?php
 }
?>

Is this bad to do, or is it better to use echo() like this:

<?php
 if ($var == true)
 {
   echo ("<p>Some text here</p>");
 }
 else
 {
   echo ("<p>Some different text</p>");
 }
?>

I find it much easier to use ?> HTML CODE <?php

But does it have any compatibility, or performance issues?

link|improve this question
feedback

closed as off topic by Diogo, Daniel Beck, random Feb 6 at 21:05

Questions on Super User are expected to generally relate to computer software or computer hardware, within the scope defined in the faq.

1 Answer

up vote 1 down vote accepted

It's not a big difference, so except in cases where you're actually experiencing performance problems you should do what is easier for you or your team to read and write.

If you're concerned about echo performance, you should use single-quoted strings if you don't need the additional interpretation features of double-quoted strings. They should be a bit faster.

link|improve this answer
Thanks, though I was concerned about the ?> HTML CODE <?php performance, not the echo performance. – Isaac Feb 6 at 21:06
@Isaac See the first paragraph. It just doesn't matter much. – Daniel Beck Feb 6 at 21:16
feedback

Not the answer you're looking for? Browse other questions tagged or ask your own question.