PHP: Difference between revisions
imported>Brett Boylen (→Syntax) |
mNo edit summary |
||
(8 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
{{subpages}} | {{subpages}} | ||
{{Infobox Programming Language | |||
| name = PHP | |||
| logo = Php-logo.png | |||
| website = www.php.net | |||
| creator = Rasmus Lerdorf | |||
| developer = The PHP Group | |||
| paradigm = imperative, object-orientated | |||
| typing = weak, dynamic | |||
| influenced_by = C, Perl, Java, C++ | |||
| licence = PHP License | |||
}} | |||
'''PHP''' is a widely-used general-purpose scripting language that is especially suited for web development and can be embedded into HTML. PHP is a ''recursive acronym'' for '''PHP: Hypertext Preprocessor'''<ref>{{cite web | '''PHP''' is a widely-used general-purpose scripting language that is especially suited for web development and can be embedded into HTML. PHP is a ''recursive acronym'' for '''PHP: Hypertext Preprocessor'''<ref>{{cite web | ||
| url=http://www.php.net/manual/en/introduction.php | | url=http://www.php.net/manual/en/introduction.php | ||
Line 27: | Line 38: | ||
In 1997, ''Zeev Suraski'' and ''Andi Gutmans'' of ''Technion - Israel Institute of Technology'' created PHP 3.0 as a complete rewrite of PHP/FI 2.0. The two decided to co-operate with Rasmus Lerdorf, and PHP 3.0 was announced as the official successor of PHP/FI 2.0. The name of the language was changed to the recursive acronym PHP: Hypertext Preprocessor. PHP 3.0 was officially released in June 1998, and at its peak, it was installed on approximately 10% of the web servers on the [[Internet]]<ref name="php_history"/>. | In 1997, ''Zeev Suraski'' and ''Andi Gutmans'' of ''Technion - Israel Institute of Technology'' created PHP 3.0 as a complete rewrite of PHP/FI 2.0. The two decided to co-operate with Rasmus Lerdorf, and PHP 3.0 was announced as the official successor of PHP/FI 2.0. The name of the language was changed to the recursive acronym PHP: Hypertext Preprocessor. PHP 3.0 was officially released in June 1998, and at its peak, it was installed on approximately 10% of the web servers on the [[Internet]]<ref name="php_history"/>. | ||
Later, Andi Gutmans and Zeev Suraski began working on a rewrite of PHP's core, which resulted in the '''Zend''' engine (comprised of their first names, ''' | Later, Andi Gutmans and Zeev Suraski began working on a rewrite of PHP's core, which resulted in the '''Zend''' engine (comprised of their first names, '''Ze'''ev and A'''nd'''i). PHP 4.0, based on the Zend engine 1.0, was officially released in May 2000. The new features in PHP 4.0 included support for more web servers, HTTP sessions, and several new language constructs. In 2002, [[Yahoo!]] began to phase out its own proprietary server-side scripting language, and started using PHP for web development<ref>{{cite web | ||
| url=http://www.radwin.org/michael/blog/2005/10/php_at_yahoo_presentation_.html | | url=http://www.radwin.org/michael/blog/2005/10/php_at_yahoo_presentation_.html | ||
| title=PHP at Yahoo! presentation from Zend/PHP Conference | | title=PHP at Yahoo! presentation from Zend/PHP Conference | ||
}}</ref>. '''Support for PHP 4 will be discontinued at 2007-12-31'''. Only criticial security fixes will be released, until 2008-08-08. The PHP development team asks to consider upgrading to PHP 5.2. | }}</ref>. '''Support for PHP 4 will be discontinued at 2007-12-31'''. Only criticial security fixes will be released, until 2008-08-08. The PHP development team asks to consider upgrading to PHP 5.2. | ||
PHP 5, driven by Zend Engine 2.0, was released on July 13, 2004. Its main features included robust support for | PHP 5, driven by Zend Engine 2.0, was released on July 13, 2004. Its main features included robust support for [[object-oriented programming]], a completely rewritten [[MySQL]] extension, a suite of interoperable ''XML'' tools, an embedded database with ''SQLite'', cleaner error handling with exceptions, integrated ''SOAP'' implementation and iterators<ref>{{cite web | ||
| url=http://www.onlamp.com/pub/a/php/2004/07/15/UpgradePHP5.html | | url=http://www.onlamp.com/pub/a/php/2004/07/15/UpgradePHP5.html | ||
| title=Why PHP 5 Rocks! | | title=Why PHP 5 Rocks! | ||
Line 46: | Line 57: | ||
===Syntax=== | ===Syntax=== | ||
PHP code is typically placed between the opening '''<?php''' tag and the closing '''?>''' tag. Alternatively, a shorter opening tag that could be used is simply '''<?'''. Unlike normal HTML tags, all code is contained within the PHP opening and closing tags, as opposed to the traditional HTML style of a separate closing tag with a forward slash, such as </example>. The syntax of the language itself is comparable and very similar to [[C (programming language)|C]]. | PHP code is typically placed between the opening '''<?php''' tag and the closing '''?>''' tag. Alternatively, a shorter opening tag that could be used is simply '''<?'''. However, using short tags while programming in PHP is not considered a good practice, as it hinders the portability of the language. The reason being, the host running the PHP script may or may not have enabled the PHP short tag option. Unlike normal HTML tags, all code is contained within the PHP opening and closing tags, as opposed to the traditional HTML style of a separate closing tag with a forward slash, such as </example>. The syntax of the language itself is comparable and very similar to [[C (programming language)|C]], [[Java programming language |Java]] and [[perl |Perl]]. For example, all statements must end with a semi-colon. An example of some PHP code is demonstrated in the following [[Hello World]] example: | ||
<pre> | <pre> | ||
Line 52: | Line 63: | ||
print "Hello World!"; | print "Hello World!"; | ||
?> | ?> | ||
</pre> | |||
==Strings== | |||
In PHP, [[string]] constants may be delimited by single quotes or double quotes. When using double quotes, the programmer may embed a variable name. Since all PHP variable names begin with a dollar sign, it's easy for the compiler to recognize them and make the substitution. | |||
<pre> | |||
$user = "Sid" | |||
print "Hello, $user!"; // This prints "Hello, Sid!" | |||
</pre> | |||
In case of ambiguity, the programmer may enclose the variable name in curly braces: | |||
<pre> | |||
$beer = "lager" | |||
print "How many $beers do you want?"; // Fails, because 's' could be part of the variable name | |||
print "How many {$beer}s do you want?"; // Ambiguity resolved | |||
</pre> | </pre> | ||
==References== | ==References== | ||
<references/> | <references/>[[Category:Suggestion Bot Tag]] |
Latest revision as of 16:00, 30 September 2024
PHP | |
---|---|
Website | www.php.net |
Created by | Rasmus Lerdorf |
Developed by | The PHP Group |
Paradigm | imperative, object-orientated |
Typing discipline | weak, dynamic |
Influenced by | C, Perl, Java, C++ |
Licence | PHP License |
PHP is a widely-used general-purpose scripting language that is especially suited for web development and can be embedded into HTML. PHP is a recursive acronym for PHP: Hypertext Preprocessor[1]. The sole implementation of PHP is provided by The PHP Group and released under the PHP License, which makes it free software.
PHP is mainly used for server-side scripting, but it can also be used for command-line scripting and for writing GUI applications (using the PHP-GTK extension)[2].
History
PHP is successor of PHP/FI (Personal Home Page/Forms Interpreter), a set of scripts created by Rasmus Lerdorf in 1995[3]. Initially, Lerdorf wrote a simple set of Perl scripts (Personal Home Page Tools) for tracking accesses to his online resume. Later, he wrote a much larger C implementation which had more functionality. On June 8, 1995, he released PHP Tools version 1.0 under GNU GPL[4]. PHP/FI 2.0 was released in November 1997, and had several thousand users.
In 1997, Zeev Suraski and Andi Gutmans of Technion - Israel Institute of Technology created PHP 3.0 as a complete rewrite of PHP/FI 2.0. The two decided to co-operate with Rasmus Lerdorf, and PHP 3.0 was announced as the official successor of PHP/FI 2.0. The name of the language was changed to the recursive acronym PHP: Hypertext Preprocessor. PHP 3.0 was officially released in June 1998, and at its peak, it was installed on approximately 10% of the web servers on the Internet[3].
Later, Andi Gutmans and Zeev Suraski began working on a rewrite of PHP's core, which resulted in the Zend engine (comprised of their first names, Zeev and Andi). PHP 4.0, based on the Zend engine 1.0, was officially released in May 2000. The new features in PHP 4.0 included support for more web servers, HTTP sessions, and several new language constructs. In 2002, Yahoo! began to phase out its own proprietary server-side scripting language, and started using PHP for web development[5]. Support for PHP 4 will be discontinued at 2007-12-31. Only criticial security fixes will be released, until 2008-08-08. The PHP development team asks to consider upgrading to PHP 5.2.
PHP 5, driven by Zend Engine 2.0, was released on July 13, 2004. Its main features included robust support for object-oriented programming, a completely rewritten MySQL extension, a suite of interoperable XML tools, an embedded database with SQLite, cleaner error handling with exceptions, integrated SOAP implementation and iterators[6].
Usage
PHP is mainly used as a server-side scripting language in web-development. It runs on many web-servers such as Apache, lighttpd, and IIS. PHP will run under almost all operating systems and chip sets.
PHP is commonly used as the "P" in LAMP (Linux, Apache, MySQL and PHP/Perl/Python). Popular PHP applications include Drupal, Joomla, MediaWiki, phpBB, and WordPress. Many web application frameworks, such as Symfony and CakePHP are also available for PHP.
Syntax
PHP code is typically placed between the opening <?php tag and the closing ?> tag. Alternatively, a shorter opening tag that could be used is simply <?. However, using short tags while programming in PHP is not considered a good practice, as it hinders the portability of the language. The reason being, the host running the PHP script may or may not have enabled the PHP short tag option. Unlike normal HTML tags, all code is contained within the PHP opening and closing tags, as opposed to the traditional HTML style of a separate closing tag with a forward slash, such as </example>. The syntax of the language itself is comparable and very similar to C, Java and Perl. For example, all statements must end with a semi-colon. An example of some PHP code is demonstrated in the following Hello World example:
<?php print "Hello World!"; ?>
Strings
In PHP, string constants may be delimited by single quotes or double quotes. When using double quotes, the programmer may embed a variable name. Since all PHP variable names begin with a dollar sign, it's easy for the compiler to recognize them and make the substitution.
$user = "Sid" print "Hello, $user!"; // This prints "Hello, Sid!"
In case of ambiguity, the programmer may enclose the variable name in curly braces:
$beer = "lager" print "How many $beers do you want?"; // Fails, because 's' could be part of the variable name print "How many {$beer}s do you want?"; // Ambiguity resolved
References
- ↑ PHP:Introduction. PHP Manual.
- ↑ PHP:What can PHP do?. PHP Manual.
- ↑ 3.0 3.1 PHP:History. PHP Manual.
- ↑ Announce: Personal Home Page Tools (PHP Tools).
- ↑ PHP at Yahoo! presentation from Zend/PHP Conference.
- ↑ Adam Trachtenberg (2004-07-15). Why PHP 5 Rocks!.