9

I was simply going through the tutorial of PHP there I found that we can write our PHP code using <script language="php"></script> tag also, and I was trying to figure out the difference between this and <?php ?> tag and advantages or disadvantages but didn't found anything, can anyone tell me the difference please.

Thanks in advance.

Dheeraj Agrawal
  • 2,347
  • 11
  • 46
  • 63
  • possible duplicate of [Major advantages and disadvantages in using , <% in php](http://stackoverflow.com/questions/6909303/major-advantages-and-disadvantages-in-using-php-script-language-ph) – BoltClock Apr 02 '12 at 06:13
  • @BoltClock'saUnicorn except the accepted answer isn't very accurate. – Yahel Apr 02 '12 at 06:16
  • 1
    @yahelc: Yeah... [php] really needs better answers. – BoltClock Apr 02 '12 at 06:16
  • thanks for the reply, same thing was running in my mind to, but I was thinking might be there is any difference, but by looking all the answers I guess there is not. – Dheeraj Agrawal Apr 02 '12 at 06:37

4 Answers4

16

I think, in terms of semantics there is no advantages or disadvantages. According to PHP manual:

There are four different pairs of opening and closing tags which can be used in PHP. Two of those, <?php ?> and <script language="php"></script>, are always available.


Also, note that:

If you are embedding PHP within XML or XHTML you will need to use the <?php ?> tags to remain compliant with standards.

Anyway, the <?php ?> is the most commonly used and recommended to use it.

NOTE: Script tags <script language="php"></script> and ASP tags <% %> are removed from PHP 7.

Victor
  • 5,493
  • 1
  • 27
  • 28
4

They both work (much to my surprise).

However, <?php ?> is by far the most common construction. You're much more likely to confuse fellow coders if you use the very rare deprecated <script> method.

As a result, you should use <?php ?> merely to avoid confusion or potential compatibility problems across implementations.

Yahel
  • 37,023
  • 22
  • 103
  • 153
0

I decided to use <?php because I experienced some problems using the popular phpStorm IDE. It does not support <script>. Neither syntax highlighting nor line breaks point work using the <script> method. Maybe this information is useful for someone else too.

Silicomancer
  • 8,604
  • 10
  • 63
  • 130
0

Always use <?php ?> because its default and works on every configuration. Other scopes may not be open from php configuration. And they will deprecate

safarov
  • 7,793
  • 2
  • 36
  • 52