PHP (PHP Hypertext Preprocessor)

While HTML can be useful on its own, the majority of websites today no longer use static pages. In order to add dynamic content to a page, a scripting language such as PHP must be used. PHP stands for Hypertext Preprocessor, and as its name implies, it processes the page before sending it off to the browser to be viewed. It is important to remember that once PHP has processed the page, it will be completely static in your browser.

PHP is server-side only, so the browser will not be able to directly manipulate any of the variables or call any of the functions defined in PHP on the server. Therefore, in order to pass information back and forth, we must make a call to a new page, generally via an HTML form, or in more advanced cases, using JavaScript.

There is wide range of PHP libraries:

connet Network connectivity (e.g. access FTP, IMAP, SMTP, etc.)
connet Socket programming
connet Database connectivity (e.g. MySQL, dBase, Oracle, etc.)
connet XML/XSLT manipulation
connet Image manipulation

All PHP code must be enclosed within its opening and closing tags (<?php code(); ?>). These tags can be opened and closed anywhere within a document, allowing you to place PHP within other document types, such as HTML.
We will take advantage of this below to make the HTML page from last week’s lab dynamic by reading images from a directory and generating the HTML to display them to the user.
One difference between PHP and languages you may have used in the past is that PHP has no types. When you define a funtion, there is no defined return type (you can return anything or nothing), and the parameters can be of any type available to you. You can also return in some cases and not in others. As a result, you may have to do extra checking to ensure that invalid input will not cause your program to behavior incorrectly.
There is a great deal of documentation available on the web for PHP. The best starting place is http://php.net, where you can find documentation and examples for every function included in PHP. PHP combined with MySQL are cross-platform (you can develop in Windows and serve on a Unix platform)

Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do this. In PHP we have the following conditional statements:

connet if statement - use this statement to execute some code only if a specified condition is true
connet if...else statement - use this statement to execute some code if a condition is true and another code if the condition is false
connet if...elseif....else statement - use this statement to select one of several blocks of code to be executed
connet switch statement - use this statement to select one of many blocks of code to be executed