#native_company# #native_desc#
#native_cta#

PHP Basics: Intro to PHP

By Stirling Hughes
on December 18, 2007

In this article we’ll introduce you to one of the Internet’s
hottest and fastest growing server side programming languages, PHP.
PHP (or Personal HomePage Tools) was created by Rasmus Lerdorf over
three years ago to track visitors to his homepage. PHP has since
evolved into a powerful server-side markup language with syntax
that resembles a mix between Perl and C.

Why Use PHP

Most Web developers know that Web pages are more than pretty
pictures and text; these days, even the most amateur of sites
strive to have some sort of animation or interactivity. Most of
the higher end sites have features such as discussion forums,
search engines and/or shopping carts. PHP enables you to add
features quickly.
The old fashioned approach to adding interactivity was to use CGI
scripts in Perl. The problem is that CGI is not very scalable;
each new request to a CGI script requires the server to start a
new process in the kernel, which uses both CPU time and memory,
making CGI scripts much slower which in turn make multiple
concurrent CGI scripts run very slowly. PHP solves this problem
by becoming a part of the Web server itself, saving the end user
a considerable amount of load time.
Another reason to use PHP is because it’s free. That’s right, PHP
is an open source project, meaning that any user can download both
the source code and executables for PHP and install them on their
computer for free. Because PHP is open source, it is solid and is
constantly being improved by many experienced programmers. It is
currently available for all major platforms.
Finally, PHP is easy. If you know C or Perl, learning PHP is a
cinch. The language is a mix between the two, taking the best
features from both. Plus PHP adds features to solve common
problems that programmers often encounter when programming for the
Web. For example, you can embed PHP code directly into an HTML file,
whereas in Perl and C you would have to use additional print
statements to output HTML. Another advantage to PHP is its native
database support for 12 databases (including mSQL and mySQL), which
allows access to the databases directly through SQL statements. And
if you don’t know either of these programming languages, then PHP
is an excellent gateway into the world of programming.

What is PHP?

So now that I’ve whetted your appetite, let’s learn some more about PHP. To start off I’ll throw some simple PHP code at you (this assumes you understand HTML):

basic.php3

1: <html>
2: <head>
3: <title>A Basic PHP page</title>
4: </head>
5: <body bgcolor="#ffffff" text="#000000">
6: <?php
7:  $date = date( "l F d, Y" );
8:  print( $date );
9:  ?>
10: </body>
11: </html>