In PHP is it ok to use ?> TEXT <?php instead of echo()

1

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?

Isaac

Posted 2012-02-06T20:27:38.157

Reputation: 123

Question was closed 2012-02-06T21:05:25.630

Answers

1

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.

Daniel Beck

Posted 2012-02-06T20:27:38.157

Reputation: 98 421

Thanks, though I was concerned about the ?> HTML CODE <?php performance, not the echo performance. – Isaac – 2012-02-06T21:06:34.430

@Isaac See the first paragraph. It just doesn't matter much. – Daniel Beck – 2012-02-06T21:16:39.560