Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

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

Questions on Super User are expected to relate to computer software or computer hardware within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer 1

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.

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

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