/    Sign up×
Community /Pin to ProfileBookmark

<?= replacement?

Ok, probably a dumb question…

…but you used to be able to do the whole <?=$var?> thing to echo out variables…

…but since <? is no longer proper and <?php is, is there any other way to echo out variables other than doing <?php echo $var; ?> ?

Thanks for any help with this ?

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@Declan1991Aug 15.2008 — No, you either use the shorthand or not.

<?php echo $var; ?>

is the only way.
Copy linkTweet thisAlerts:
@NogDogAug 15.2008 — The long forms always work, the short forms only if your PHP configuration specifies that short_open_tag is ON. Thus I always use the long form to be on the safe side and make sure that at least that is never a portability issue.
Copy linkTweet thisAlerts:
@felgallAug 16.2008 — The medium form and the long form both always work.

Medium Form:

<?php echo $var; ?>

Long Form:

<script language="php">echo $var;</script>

The two short forms can both be turned off so that you can use <? ?> and <% %> in your page without their being interpreted as the start end end of PHP.

Since you never know when you will need to have the script able to work when the short forms are off those versions are best avoided. The long form is so much longer than the others that it is seldom used since the medium form also always works and is a lot shorter.
Copy linkTweet thisAlerts:
@NogDogAug 16.2008 — I wonder if anyone actually uses the <script> tag for PHP? I know I'm too lazy to do so. ?
Copy linkTweet thisAlerts:
@felgallAug 16.2008 — I suppose if you had a situation where there are lots of <? ?> references within the content then some people might consider using the script tag around the actual PHP in order to make it clearer as to which are which. Even with short tags off if you have dozens of ?> in the actual content then telling where the PHP actually finishes could end up being difficult.

I can't think of any reason why anyone would have lots of such content though unless they were writing about PHP and even then a better alternative would be to use ?&gt; for the content as that would be the smaller change.
Copy linkTweet thisAlerts:
@Stephen_PhilbinAug 16.2008 — I always disable short tags as compile time for the same reason I always use "<?php": compatibility with XML.
×

Success!

Help @tgrk35 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...