zeboidlund
zeboidlund

Reputation: 10137

Embedding PHP in HTML

I was curious to see if the following:

<td><?=JText::_('_EMAIL')?></td>

is equivalent to:

<td><?php echo JText::_('_EMAIL')?></td>

I know it's possible to do:

<td class=<?=$somestring;?>> <!-- markup --> </td>

but, in the case of there being an expression tag which is not necessarily linking up with an attribute, I wasn't sure if it would produce the same effect.

Is this true?

Upvotes: 0

Views: 76

Answers (2)

Quentin
Quentin

Reputation: 943556

<?php and ?> just look like SGML/XML processing instructions. As far as PHP is concerned, it is looking for them in text, not markup. It doesn't matter where you put them.

Upvotes: 1

deceze
deceze

Reputation: 522081

PHP tags don't care where they start or end. PHP does not evaluate anything outside of <?php ?> tags, so it doesn't matter where they occur. Yes, all three snippets will output content. <?= is simply the shorthand version of <?php echo, and BTW, it's discouraged because "short open tags" can be disabled, whereas <?php always works.

Upvotes: 3

Related Questions