Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 690071 of PHP

  • Revision slug: Glossary/PHP
  • Revision title: PHP
  • Revision id: 690071
  • Created:
  • Creator: klez
  • Is current revision? No
  • Comment added web literacy tags

Revision Content

Summary

PHP is a server-side scripting language, designed for web development. It can also be used as a standalone general-purpose programming language and supports object-oriented programming. It's syntax is much like C/C++ and also has some similarity with Perl.

In Depth

A bit of history

PHP development began in 1994 when Rasmus Lerdorf wrote a series of Common Gateway Interface (CGI) binaries in C, which he used to maintain his personal homepage. He extended them to add the ability to work with web forms and to communicate with databases, and called this implementation "Personal Home Page/Forms Interpreter" or PHP/FI.

PHP/FI could be used to build simple, dynamic web applications. Lerdorf initially announced the release of PHP/FI as "Personal Home Page Tools (PHP Tools) version 1.0" publicly to accelerate bug location and improve the code, on the Usenet discussion group  comp.infosystems.www.authoring.cgi  on June 8, 1995. This release already had the basic functionality that PHP has as of 2013. This included Perl-like variables, form handling, and the ability to embed HTML. The syntax resembled that of Perl but was simpler, more limited and less consistent.

 

Concept and syntax

PHP is a server side scripting language. It can embedded in html code. Or even can be used in standalone php apps. A nomal php code can be seen as:

<?php echo '<p>Hello World</p>'; ?>

However, as PHP does not need to be embedded in HTML or used with a web server, the simplest version of a Hello World program can be written like this, with the closing tag omitted as preferred in files containing pure PHP code (prior to PHP 5.4.0, this short syntax for <tt style="font-family: monospace, Courier;">echo()</tt> only works with the <tt style="font-family: monospace, Courier;">short_open_tag </tt>configuration setting enabled, while for PHP 5.4.0 and later it is always available):

<?= 'Hello world';

The PHP interpreter only executes PHP code within its delimiters. Anything outside its delimiters is not processed by PHP (although non-PHP text is still subject to control structures described in PHP code). The most common delimiters are <?php to open and ?> to close PHP sections. <script language="php"> and</script> delimiters are also available, as are the shortened forms <? or <?= (which is used to echo back a string or variable) and ?> as well as ASP-style short forms <% or <%= and %>. Short delimiters make script files less portable, since support for them can be disabled in the local PHP configuration, and they are therefore discouraged. The purpose of all these delimiters is to separate PHP code from non-PHP code, including HTML.

The first form of delimiters, <?php and ?>, in XHTML and other XML documents, creates correctly formed XML "processing instructions". This means that the resulting mixture of PHP code and other markup in the server-side file is itself well-formed XML.

 

Resources

Revision Source

<h2 id="Summary" style="line-height: 30px; font-size: 2.14285714285714rem;">Summary</h2>
<p>PHP is a server-side scripting language, designed for web development. It can also be used as a standalone general-purpose programming language and supports <a href="https://en.wikipedia.org/wiki/Object-oriented_programming">object-oriented programming</a>. It's syntax is much like C/C++ and also has some similarity with Perl.</p>
<h2 id="In_Depth" style="line-height: 30px; font-size: 2.14285714285714rem;">In Depth</h2>
<h3 id="A_bit_of_history" style="line-height: 24px; font-size: 1.71428571428571rem;">A bit of history</h3>
<p style="margin-top: 0.5em; margin-bottom: 0.5em; color: rgb(37, 37, 37); font-family: sans-serif;"><span style="line-height: 22.3999996185303px;">PHP development began in 1994 when&nbsp;<a href="https://en.wikipedia.org/wiki/Rasmus_Lerdorf" style="color: rgb(11, 0, 128); background: none;" title="Rasmus Lerdorf" wotsearchprocessed="true">Rasmus Lerdorf</a>&nbsp;wrote a series of&nbsp;<a href="https://en.wikipedia.org/wiki/Common_Gateway_Interface" style="color: rgb(11, 0, 128); background: none;" title="Common Gateway Interface" wotsearchprocessed="true">Common Gateway Interface</a>&nbsp;(CGI) binaries in C,</span><span style="font-size: 11px; line-height: 11px;">&nbsp;</span><span style="line-height: 22.3999996185303px;">which he used to maintain his&nbsp;</span><a class="mw-redirect" href="https://en.wikipedia.org/wiki/Personal_homepage" style="line-height: 22.3999996185303px; color: rgb(11, 0, 128); background-image: none; background-attachment: initial; background-color: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;" title="Personal homepage" wotsearchprocessed="true">personal homepage</a><span style="line-height: 22.3999996185303px;">. He extended them to add the ability to work with&nbsp;</span><a class="mw-redirect" href="https://en.wikipedia.org/wiki/Web_form" style="line-height: 22.3999996185303px; color: rgb(11, 0, 128); background-image: none; background-attachment: initial; background-color: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;" title="Web form" wotsearchprocessed="true">web forms</a><span style="line-height: 22.3999996185303px;">&nbsp;and to communicate with&nbsp;</span><a href="https://en.wikipedia.org/wiki/Database" style="line-height: 22.3999996185303px; color: rgb(11, 0, 128); background-image: none; background-attachment: initial; background-color: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;" title="Database" wotsearchprocessed="true">databases</a><span style="line-height: 22.3999996185303px;">, and called this implementation "Personal Home Page/Forms Interpreter" or PHP/FI.</span></p>
<p style="margin-top: 0.5em; margin-bottom: 0.5em; line-height: 22.3999996185303px; color: rgb(37, 37, 37); font-family: sans-serif;">PHP/FI could be used to build simple, dynamic&nbsp;<a href="https://en.wikipedia.org/wiki/Web_application" style="color: rgb(11, 0, 128); background: none;" title="Web application" wotsearchprocessed="true">web applications</a>. Lerdorf initially announced the release of PHP/FI as "Personal Home Page Tools (PHP Tools) version 1.0" publicly to accelerate&nbsp;<a href="https://en.wikipedia.org/wiki/Software_bug" style="color: rgb(11, 0, 128); background: none;" title="Software bug" wotsearchprocessed="true">bug</a>&nbsp;location and improve the code, on the&nbsp;<a href="https://en.wikipedia.org/wiki/Usenet" style="color: rgb(11, 0, 128); background: none;" title="Usenet" wotsearchprocessed="true">Usenet</a>&nbsp;discussion group&nbsp;
 <i>
  comp.infosystems.www.authoring.cgi</i>
 &nbsp;on June 8, 1995.&nbsp;This release already had the basic functionality that PHP has as of 2013. This included Perl-like variables, form handling, and the ability to embed HTML. The&nbsp;<a href="https://en.wikipedia.org/wiki/Syntax" style="color: rgb(11, 0, 128); background: none;" title="Syntax" wotsearchprocessed="true">syntax</a>&nbsp;resembled that of Perl but was simpler, more limited and less consistent.</p>
<p>&nbsp;</p>
<h3 id="Concept_and_syntax" style="line-height: 24px; font-size: 1.71428571428571rem;">Concept and syntax</h3>
<p>PHP is a server side scripting language. It can embedded in html code. Or even can be used in standalone php apps. A nomal php code can be seen as:</p>
<p><code>&lt;?php echo '&lt;p&gt;Hello World&lt;/p&gt;'; ?&gt;</code></p>
<p style="margin-top: 0.5em; margin-bottom: 0.5em; line-height: 22.3999996185303px; color: rgb(37, 37, 37); font-family: sans-serif;">However, as PHP does not need to be embedded in HTML or used with a web server, the simplest version of a Hello World program can be written like this, with the closing tag omitted as preferred in files containing pure PHP code&nbsp;(prior to PHP 5.4.0, this short syntax for&nbsp;<code><tt style="font-family: monospace, Courier;">echo()</tt></code>&nbsp;only works with the&nbsp;<code><tt style="font-family: monospace, Courier;">short_open_tag&nbsp;</tt></code>configuration setting enabled, while for PHP 5.4.0 and later it is always available):</p>
<div dir="ltr">
 <div>
  <code>&lt;?= 'Hello world'; </code></div>
</div>
<p style="margin-top: 0.5em; margin-bottom: 0.5em; line-height: 22.3999996185303px; color: rgb(37, 37, 37); font-family: sans-serif;">The PHP interpreter only executes PHP code within its&nbsp;<a href="https://en.wikipedia.org/wiki/Delimiter" style="color: rgb(11, 0, 128); background: none;" title="Delimiter" wotsearchprocessed="true">delimiters</a>. Anything outside its delimiters is not processed by PHP (although non-PHP text is still subject to&nbsp;<a class="mw-redirect" href="https://en.wikipedia.org/wiki/Control_structure" style="color: rgb(11, 0, 128); background: none;" title="Control structure" wotsearchprocessed="true">control structures</a>&nbsp;described in PHP code). The most common delimiters are&nbsp;<code>&lt;?php</code>&nbsp;to open and&nbsp;<code>?&gt;</code>&nbsp;to close PHP sections.&nbsp;<code>&lt;script language="php"&gt;</code>&nbsp;and<code>&lt;/script&gt;</code>&nbsp;delimiters are also available, as are the shortened forms&nbsp;<code>&lt;?</code>&nbsp;or&nbsp;<code>&lt;?=</code>&nbsp;(which is used to echo back a&nbsp;<a href="https://en.wikipedia.org/wiki/String_(computer_science)" style="color: rgb(11, 0, 128); background: none;" title="String (computer science)" wotsearchprocessed="true">string</a>&nbsp;or&nbsp;<a class="mw-redirect" href="https://en.wikipedia.org/wiki/Variable_(programming)" style="color: rgb(11, 0, 128); background: none;" title="Variable (programming)" wotsearchprocessed="true">variable</a>) and&nbsp;<code>?&gt;</code>&nbsp;as well as&nbsp;<a href="https://en.wikipedia.org/wiki/Active_Server_Pages" style="color: rgb(11, 0, 128); background: none;" title="Active Server Pages" wotsearchprocessed="true">ASP</a>-style short forms&nbsp;<code>&lt;%</code>&nbsp;or&nbsp;<code>&lt;%=</code>&nbsp;and&nbsp;<code>%&gt;</code>. Short delimiters make script files less portable, since support for them can be disabled in the local PHP configuration, and they are therefore discouraged.&nbsp;The purpose of all these delimiters is to separate PHP code from non-PHP code, including HTML.</p>
<p style="margin-top: 0.5em; margin-bottom: 0.5em; line-height: 22.3999996185303px; color: rgb(37, 37, 37); font-family: sans-serif;">The first form of delimiters,&nbsp;<code>&lt;?php</code>&nbsp;and&nbsp;<code>?&gt;</code>, in&nbsp;<a href="https://en.wikipedia.org/wiki/XHTML" style="color: rgb(11, 0, 128); background: none;" title="XHTML" wotsearchprocessed="true">XHTML</a>&nbsp;and other&nbsp;<a href="https://en.wikipedia.org/wiki/XML" style="color: rgb(11, 0, 128); background: none;" title="XML" wotsearchprocessed="true">XML</a>&nbsp;documents, creates correctly formed XML "processing instructions".&nbsp;This means that the resulting mixture of PHP code and other markup in the server-side file is itself well-formed XML.</p>
<p style="margin-top: 0.5em; margin-bottom: 0.5em; line-height: 22.3999996185303px; color: rgb(37, 37, 37); font-family: sans-serif;">&nbsp;</p>
<h2 id="Resources">Resources</h2>
<ul>
 <li><a href="https://php.net/">PHP - Offical Site</a></li>
 <li><a href="https://en.wikipedia.org/wiki/PHP">PHP - Wikipedia, the free encyclopedia</a></li>
 <li><a href="https://www.codecademy.com/tracks/php">Learn PHP - Codecademy </a></li>
</ul>
Revert to this revision