New Technologies and What They Mean To You: Part 2 - PHP
(Page 2 of 5 )
Definition PHP (PHP Hypertext Processor) is an HTML-embedded, server-side, cross-platform scripting language used to create dynamic web pages. PHP is open source software.
PHP is a server side language designed to be able to handle web-based applications and processing. When a PHP script is requested from the server, it is parsed (read) for instructions that are then executed. The resulting HTML code is then sent to the browser.
As PHP is open source, it can be ran on many different types of servers, such as Apache, IIS etc. This fact has lead to the rapid adoption of PHP by the web development community, and it is now one of the most popular server side languages.
The latest version of PHP -- version 4 -- is built upon the Zend parsing engine, which was written by Andi Gutmans and Zeev Suraski. Andi and Zeev adopted the PHP language after version 2 and have been responsible for all major releases since (including a complete overhaul).
PHP4 now includes support for many more web servers, HTTP sessions, output buffering, more secure ways of handling user input and several new language constructs.
What It Really Is So that's what PHP is on paper, but what does it really do? Two things that are instantly attractive are that it's open source, and so it has a low development cost and support and assistance are readily available through the active and helpful PHP community.
For experienced developers in Java, C, C++ or even JavaScript, the syntax of PHP is both logical and familiar. The developers have taken care to ensure that the language is not overly complicated by, for example, naming functions logically ie: strtoupper() and arraypop(). This makes PHP a solid language for anyone looking to take the leap from static HTML pages to dynamic web sites.
The most common application of PHP is, undoubtedly, web-based applications which utilize a MySQL database, which means that developers can effectively create fast web applications. PHP provides support for many other databases as well, including Microsoft SQL Server, Oracle and Microsoft Access.
It has proven to be a viable and stable solution for everything from personal to corporate to eCommerce web sites. It also comes with a wide range of other features such as, XML support, Java servlet support, native session handling and IMAP functions amongst others.
Overall PHP is a strong option for those looking to graduate from the basics of web design. As well as being easy to pick up, it offers many advanced functions that experienced developers will appreciate.
Advantages - Strong support community
- Ease of use for experienced developers
- Installed on nearly all web hosts
- Cross-platform
- Open Source
Disadvantages - Strong learning curve for inexperienced developers
- Security risks for new developers, due to the power PHP is given
Examples For examples of PHP usage, as well as the full manual, go to
http://www.php.net/manual. Here are some basic PHP examples:
PHP Start & End Tags:
<?php ... ?> or <? ... ?> Display Configuration Information:
<? phpinfo(); ?> Comparison Operators:
$a == $b Checks if the value held in $a is the same as that held in $b
$a === $b Same as before but also checks if they are the same type (string, number)
$a != $b Checks if the value held in $a is not equal to that held in $b
$a < $b Returns true if the value held in $a is LESS THAN that held in $b
$a > $b Returns true if the value held in $a is GREATER THAN that held in
MySQL Database Connection:
If(!$link = mysql_connect("mysql_host", "mysql_login", "mysql_password")) {
echo("Error connecting to the database host: " . mysql_error());
}
if(!mysql_select_db("devarticles")) {
echo("Couldnt connect to the database because " . mysql_error());
}
echo("WOOHOO! Ready to start executing querys on the database."); Similar Technologies Really, any web based scripting language is "similar" to PHP, in that it fulfills the same goals. We will look at most of these during the rest of this article series:
- ASP: By far the most hated rival of the PHP community. ASP is Microsoft's proprietary scripting language. While it does run on Linux under interpreter’s such as Sun’s ASP ONE, it shines on Windows NT and Windows 2000 machines.
- ColdFusion: ColdFusion is Macromedia's offering for web-based dynamic content. While it isn’t technically "scripting", as it is based on an HTML-like tag structure, it does fulfill the same goal of providing dynamic web pages.
Links There are many places to find out information about PHP, and there are literally thousands of sites that will help you on your way. Some of the best for both of these are:
DevArticles PHP section Hotscripts list of tutorials Official PHP manualNext: ASP >>
More ASP Articles
More By Jeremy Wright