/    Sign up×
Community /Pin to ProfileBookmark

why some php code can use <? ….?> instead of <?php…?>

this is really a beginner’s question….

I found that my machine as a local server can only run the code of <?php..?>

but another remote server can run the code of <?….?>

like

[code=php]
<?
echo “Greetings from PHP.”;
?>
[/code]

does not work on my machine but work on another server. why?

I am using apache on windows xp.

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@FangMay 31.2008 — short_open_tag is set to "1" in php.ini (default) which does not allow the [I]<? ?>[/I]

It is considered best practice to use [I]<?php ?>[/I]
Copy linkTweet thisAlerts:
@felgallMay 31.2008 — You could also use

<script type="application/php"> </script>

if you want to use an even longer version of the tags.
Copy linkTweet thisAlerts:
@NogDogJun 01.2008 — You could also use

<script type="application/php"> </script>

if you want to use an even longer version of the tags.[/QUOTE]

[url=http://us.php.net/manual/en/language.basic-syntax.php]According to the manual[/url] (with my emphasis added):
There are four different pairs of opening and closing tags which can be used in php. Two of those, <?php ?> and [b]<script [color=red]language="php"[/color]> </script>[/b], are always available. The other two are short tags and ASP style tags, and can be turned on and off from the php.ini configuration file. As such, while some people find short tags and ASP style tags convenient, they are less portable, and generally not recommended.[/quote]

Also, I believe the plan is to not even have the short_open_tag option available at all in PHP 6, so in addition to the other good reasons to avoid "<?" and "<?=", forward compatibility is another reason.
Copy linkTweet thisAlerts:
@usfishauthorJun 01.2008 — Thank you guys!
Copy linkTweet thisAlerts:
@felgallJun 01.2008 — Oops. I misremembered how to code the PHP script tag. For some reason I thought it was similar to an HTML script tag and of course HTML script tags don't have a language attribute. I wonder why they didn't make the PHP script tag similar to the HTML one?
Copy linkTweet thisAlerts:
@NogDogJun 01.2008 — Oops. I misremembered how to code the PHP script tag. For some reason I thought it was similar to an HTML script tag and of course HTML script tags don't have a language attribute. I wonder why they didn't make the PHP script tag similar to the HTML one?[/QUOTE]
I figured you were diligently trying to write valid, strict [X]HTML. ?
×

Success!

Help @usfish 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.19,
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,
)...