This is mainly about how you like reading your code.
An IDE that has autocompletion / code suggestions is best used
<?php if (...) { ?>, so the autocompletion / suggestion functions know when to use html and php suggestions for your code. And, of course, it's nice to choose a coding style that is easy to read later.
As far as I know, code highlighting does not work and should not work inside
echo '<div class="c"><h2>...';
:
, , . ,
echo "<div>$var1<h1>$var2</h1>...";
(less writing), , :
<?php
?><div><?php echo $var1; ?><h1><?php echo $var2; ?></h1>...
/ :
<?= ?> , , PHP ( // ) short_open_tag. PHP Since PHP 5.4.0, <?= is always available.
PHP ?
PHP echo vs PHP
<?php ?> PHP: Hypertext Preprocessor, - , echo '<html><here>'; , - , 100000 echo print + <?php ?> , echo, cpu, , .
PHP script?
php.net/manual/en/tokens.php
PHP
:
1,77 .: 1 000 000 $var = rand(0, 1); echo 'Foo Bar '.$var;
1,61 .: 1 000 000 $var = rand(0, 1); ?>Foo Bar <?php echo $var; ?><?php
1.83s.: 1 000 000 $var = rand(0, 1); echo "Foo Bar $var";
, , / . ,
if (...) { echo "something"; }
<?php if (...) { ?>something<?php } ?>
echo "...";, ?>...<?php html . .
, :
, php , ?>text<?php echo "text"; , - -.
: , ?>text<?php echo "text"; .
:
, , , ( PHP docs) , , , , , , echo:
if ( get_field('field_name') ) {
echo "<p>HTML can go here by echo'ing it</p>";
}
:
php.net/manual/en/control-structures.alternative-syntax.php
php.net/manual/en/language.basic-syntax.phpmode.php
php.net/manual/en/language.types.string.parsing.complex
google .
, alternate :
<?php if ($a == 5): ?>
A is equal to 5
<?php endif; ?>
UPDATE:
{ } <?php ?> : control-structures.intro language.basic-syntax.phpmode.php , (. ).