Subscribe

PHP Shorthand ( <? vs. <?php )

Posted by Garth on Saturday, May 16, 2009

Am doing some web dev (and learning PHP in the process - I know, late to the game, but better late than never), and every sample script I downloaded was in shorthand - i.e. the opening tags for php script were simply <? instead of the more traditional <?php.  I'm using WampServer, which is quite a nifty little package for doing this type of dev on Windows, but I couldn't figure out for the life of me how to make it understand the shorthand.  Then I realized that I was making it too difficult.  All you do is left click the WAMPSERVER icon in the systray and select PHP > PHP Settings > short open tag.  I also dug around in the C:\wamp\bin\php\php5.2.9-2 directory and found the php.ini which also contains this setting:

short_open_tag = Off
But when I edited it and restarted the services nothing had changed, so maybe something in Wamp overrides this.

Also, this is one of those that I decided to blog about because searching google for <? and <?php when you don't know the term "shorthand" is a big PITA, so hopefully this helps someone.

5 comments:

Rob Drimmie said...

They're also frequently called asp-style tags.

Sorry, this soap box slipped out and suddenly I'm standing on it: They are also frequently frowned upon because working with xml on a php server becomes a pain because the xml declaration* gets parsed by the php parser. That's kind of an edge case though.

* starts with the same two characters which in combination make blogger say I'm a bad person for trying to inject into your site.

Garth said...

Ya, I don't plan on using them due to bad form, but blogger really has an issue with them. The first time I posted this it had parsed them and caused all sorts of weird formatting issues. So I fixed(?) it, but when I got your comment emailed to me it was messed:

Rob Drimmie has left a new comment on your post "PHP Shorthand ( ":

They're also frequently called asp-style tags. ...

Everything after after and including PHP Shorthand (" was a link back to the post, as would normally just be the subject.

MoM:) said...

So, hope you did the tours--call it experience and enjoy the adventure. We would all love to hear about it-solo is okay--just not the best for you!!

Gregg said...

See the easier thing would be to just use ASP.Net and Visual Studio then you wouldn't run into these problems at all.

heh.

worldthreat said...

You are the Bomb! :)

Subscribe to: Post Comments (Atom)