Introduction to PHP

Introduction to PHP

PHP is a server-side language, which means it runs on the server before anything is sent to the user's computer. This is in contrast to client-side languages, where the code is sent to the user's computer to be processed locally with languages like JavaScript.

History of PHP

PHP was created in 1994 by Rasmus Lerdorf. PHP began as a set of CGI scripts developed to track views of his resume online. Rasmus continued adding scripts to his collection so he could do more with his websites. Over time, some friends began to use it as well.

By June 1995, enough of a framework was in place that Rasmus decided to make PHP public. As others embraced it, and began to submit their own work, PHP grew.

By version 3 it was decided that the time had come for a more professional name. In homage to its original name of Personal Home Page, the PHP acronym was kept, but was changed to a recursive representation of hypertext preprocessor. PHP was now an independent language, with object-oriented capabilities, high extensibility, and had a growing following.

With strong semblance to languages like C++ and Perl, the goal was to create a language that allowed fast development of dynamic pages.

Server Side Language

Some advantages to server-side languages are that the code is hidden from the user, and secures what is taking place in the background. It also reduces the work load that the user’s computer is burdened with. However, this also means the server must be powerful enough to support the number of users requesting pages, as it must bear the brunt of the computation.

PHP is a parsing engine, which means it examines the php file, performs any php related tasks it finds, and passes the result to the web server. This makes it an interpreted language, as the output and script are run on demand, as opposed to a compiled language where the code is transformed and saved into a runnable form.

PHP File Extension and Code

PHP uses a special file format to identify its contents. When you want to use PHP in a file, you need to set the file format as .php. The PHP code begin with <?php and end with ?>. These are tags, just like in HTML, and are used to mark the start and end of a section of code that contains PHP.

<?php ... ?>

This PHP file can include any HTML, as well as PHP scripting code.

PHP Websites

In contrast with HTML sites, PHP sites are dynamically generated. Instead of the site being made up of a large number of static HTML files, a PHP site may consist of only a handful of template files. The template files describe only the structure of the site using PHP code, while the web content is pulled from a database and the style formatting is from Cascading Style Sheets (CSS). This allows for site-wide changes from a single location, providing a flexible web site that is easy to design, maintain, and update.

When creating web sites with PHP, a content management system (CMS) is generally used. A CMS provides a fully integrated platform for web site development consisting of a back end and a front end. The front end is what visitors see when they arrive at the site, whereas the back end is where the site is configured, updated, and managed by an administrator.

Outputting Text

Printing text in PHP is done by either typing echo or print followed by the output. Each statement must end with a semicolon (;) in order to separate it from other statements.

echo "Hello World";
print "Hello World";

When a request is made for the PHP web page, the script is parsed on the server and sent to the browser as only HTML. If the source code for the web site is viewed, it will not show any of the server-side code that generated the page - only the HTML output.

Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive