Opening php file declaration question
I've inherited an existing php web site. The file names end with the php extension and the code appears to be php.
Just wondering why the opening file declaration is "
<?" instead of "
What is the difference between the 2 and why would one be used over the other.
It's called PHP short tags. If short tags is enabled the two notations are equivalent, but short tags can be disabled on some servers so it's usually best to write the tag in full in you are in doubt.
The documentation has this to say:
<?is 3 fewer characters to type, but will be ambiguous in an XML document (
<?xml version="1.0"?>will cause a parse error) and if the short_tags setting is off, it won't work. There's also
<?=as a shortcut for
This are short tag, i recommend not to use it. There are a lot of them like <
script type="php"></script>or asp like
<% %>But i recommend to use the
<?php ?>style :-)