Domanda

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.

È stato utile?

Soluzione

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

  • Short tags <?=
  • Long version <?php echo (or print())

Altri suggerimenti

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()

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.

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top