-4

If

<?=$var?> 

is used only if short tags are enabled, then does that mean the regular version of that is:

<?php=$var?>

The second one doesn't work tho.

Arian Faurtosh
  • 17,987
  • 21
  • 77
  • 115
  • 1
    The downvotes on the question and answer were because it took me seconds to google "php short tag" and check php.net where all the info was right there, as per my answer (which is sadly downvoted sigh). There are also numerous dupes on Stack about this. – James Sep 26 '13 at 01:06

4 Answers4

5

<?php= is not valid syntax. Your choices are

  • Short tags <?=
  • Long version <?php echo (or print())
John Conde
  • 217,595
  • 99
  • 455
  • 496
3

If the short tag is enabled you can use <?=$var?>
Which is the shorter version of <?php echo $var ?>

There is nothing called <?php=$var?> You have to replace the = with echo or print()

Deepak
  • 6,684
  • 18
  • 69
  • 121
  • 1
    I have just learned that actually, short tags don't need to be enabled to use = in PHP 5.4 and higher. So your answer is not fully correct. – Arian Faurtosh Sep 26 '13 at 00:59
0

Because no one else has mentioned this, and after further searching using google... I wanted to post what I think is crucial info.

http://php.net/manual/en/function.echo.php

The following link states:

echo also has a shortcut syntax, where you can immediately follow the opening tag with an equals sign. Prior to PHP 5.4.0, this short syntax only works with the short_open_tag configuration setting enabled.

Which is very important, because there isn't a need for <?php= because <?= will work if short tags are disabled or enabled for all future versions of PHP!

This is very important as the use of all other short tags is considered futile. Anyway the use of the short echo tag is encouraged from now on. It does provide for a smoother and tidier code-base - esp. in view files. So for PHP >= 5.4.0 <?= ?> can be used without setting short_open_tag.

Arian Faurtosh
  • 17,987
  • 21
  • 77
  • 115
  • Why the down vote, all this information is true, and straight from php.net – Arian Faurtosh Sep 26 '13 at 00:57
  • @Arian To answer you, the -1 was because I don't feel you put enough effort into trying to find the answer yourself before asking. It was easy info to source. In fact you posted this answer 17 mins after your question. More importantly, you already asked this in another question yesterday and got good answers, and links to good answers to your question - http://stackoverflow.com/questions/18989102/can-var-syntax-cause-problems So your question here is a dupe of your previous question which has links to other dupes. Sorry, but it deserved -1. Just search a bit more :) – James Sep 26 '13 at 01:30
0

Always check Stack, Google, etc first, and check the PHP.net and read about it.
It's all in the manual clear as day! :)

http://php.net/manual/en/language.basic-syntax.phptags.php

When PHP parses a file, it looks for opening and closing tags, which are <?php and ?> which tell PHP to start and stop interpreting the code between them.

PHP also allows for short tags <? and ?> (which are discouraged because they are only available if enabled with short_open_tag php.ini configuration file directive, or if PHP was configured with the --enable-short-tags option.

http://www.php.net/manual/en/ini.core.php#ini.short-open-tag

This directive also affected the shorthand <?= before PHP 5.4.0, which is identical to <? echo. Use of this shortcut required short_open_tag to be on. Since PHP 5.4.0, <?= is always available.

Community
  • 1
  • 1
James
  • 4,644
  • 5
  • 37
  • 48