", "text": "<p>I was simply going through the tutorial of PHP there I found that we can write our PHP code using <code>&lt;script language="php"&gt;&lt;/script&gt;</code> tag also, and I was trying to figure out the difference between this and <code>&lt;?php ?&gt;</code> tag and advantages or disadvantages but didn't found anything, can anyone tell me the difference please.</p>\n\n<p>Thanks in advance.</p>", "answerCount": 2, "upvoteCount": 969, "dateCreated": "2012-04-02 06:10:03", "dateModified": "2022-10-20 01:05:27", "author": { "type": "Person", "name": "Dheeraj Agrawal" }, "acceptedAnswer": { "@type": "Answer", "text": "<p>I think, in terms of semantics there is no advantages or disadvantages. According to PHP manual:</p>\n\n<blockquote>\n <p>There are four different pairs of opening and closing tags which can\n be used in PHP. Two of those, <code>&lt;?php ?&gt;</code> and <code>&lt;script language="php"&gt;&lt;/script&gt;</code>, are <strong>always available</strong>.</p>\n</blockquote>\n\n<p><br>\nAlso, note that:</p>\n\n<blockquote>\n <p>If you are embedding PHP within XML or XHTML you will need to use the\n <code>&lt;?php ?&gt;</code> tags to remain compliant with standards.</p>\n</blockquote>\n\n<p>Anyway, the <code>&lt;?php ?&gt;</code> is the most commonly used and recommended to use it.</p>\n\n<p><strong>NOTE</strong>: Script tags <code>&lt;script language="php"&gt;&lt;/script&gt;</code> and ASP tags <code>&lt;% %&gt;</code> are removed from PHP 7. </p>", "upvoteCount": 122, "url": "https://exchangetuts.com/difference-between-php-and-script-languagephpscript-1640484904451094#answer-1652646724218660", "dateCreated": "2022-10-19 11:05:27", "dateModified": "2022-10-20 01:05:27", "author": { "type": "Person", "name": "Victor" } }, "suggestedAnswer": [ { "@type": "Answer", "text": "<p>They both work <sub>(much to my surprise)</sub>.</p>\n\n<p>However, <code>&lt;?php ?&gt;</code> is by far the most common construction. You're much more likely to confuse fellow coders if you use the very rare deprecated <code>&lt;script&gt;</code> method.</p>\n\n<p>As a result, you should use <code>&lt;?php ?&gt;</code> merely to avoid confusion or potential compatibility problems across implementations. </p>", "upvoteCount": 20, "url": "https://exchangetuts.com/difference-between-php-and-script-languagephpscript-1640484904451094#answer-1652646724221923", "dateCreated": "2022-10-19 11:05:27", "dateModified": "2022-10-20 01:05:27", "author": { "type": "Person", "name": "Yahel" } } ] } }
Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between <?php ?> and <script language="php"></script>

Tags:

php

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.

like image 969
Dheeraj Agrawal Avatar asked Apr 02 '12 06:04

Dheeraj Agrawal


People also ask

What is <? PHP in PHP language?

What is PHP? PHP is an acronym for "PHP: Hypertext Preprocessor" PHP is a widely-used, open source scripting language. PHP scripts are executed on the server.

How PHP is different from PHP script explain?

that is used to develop Static websites or Dynamic websites or Web applications. PHP stands for Hypertext Pre-processor, that earlier stood for Personal Home Pages. PHP scripts can only be interpreted on a server that has PHP installed. The client computers accessing the PHP scripts require a web browser only.

Is PHP a script language?

PHP (recursive acronym for PHP: Hypertext Preprocessor ) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML.

What does script mean in PHP?

A program written in PHP, or any other scripting language, is called a script. – Barmar. Mar 9, 2016 at 23:40. Generally, we refer to scripting language to define code that don't require an explicit compilation. PHP is one of the languages that don't require explicit compilation.


2 Answers

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.

like image 122
Victor Avatar answered Oct 20 '22 01:10

Victor


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.

like image 20
Yahel Avatar answered Oct 20 '22 01:10

Yahel