Introduction to PHP
PHP is a server-side scripting language, which is different from HTML and JavaScript commands that are processed in a browser (Internet Explorer or Firefox for example). Expanding on this thought, consider these differences: when your browser requests a URL (http://www.voyagerwd.com for example) the server sends the HTML / JavaScript code to your browser. Your browser has the responsibility to display the results from the HTML / JavaScript commands. There are two important points to realize:
* When you request a URL, the server sends the HTML / JavaScript to your computer for processing by the browser.
* Your browser has no capability to send programs, commands or data to the server. PHP is different. PHP commands are processed by the server before they are sent to your browser. You see the results when they are passed from the server to your browser.
Running a PHP script
To run an HTML script, you can save the script anywhere you want on your computer -such as the desktop- and it will run in your browser. Not so with PHP. PHP must be run on a server. To run a PHP program on your computer, you must install server software on your computer. A commonly used (free) server is Apache.
Creating PHP Scripts
When you write an HTML / Javascript program, PHP scripts can be included. Here is the important difference. HTML commands start with an open bracket ( < ) and end with a closing bracket ( > ), PHP commands however, starts with . You can insert PHP scripts anywhere in your Web page. When you request a URL, the server determines what is sent to your browser and what is processed on the server. PHP scripts can be included anywhere in the HTML code and the PHP will be found a processed on the server. PHP files are usually given the ".php" extension.
Simple Example
echo 'We started out in PHP'
?>
This is my heading
This is now in the PHP world
include("someFileName.inc.php")
?>
PHP Applications
PHP is used to accomplish special tasks. Some PHP commands overlap JavaScript commands but that is for another more advanced discussion. Here are a very small list of applications allowed by the PHP capability.
* PHP Mail: PHP use a mail() function to send email from a web page. The mail function allows:multiple recipients, subjects, bcc, etc.
* PHP Database Interface: PHP is used to communicate with a database. PHP ( or another server side language) is used to provide communication between an HTML form and a compatible database such as MySQL. When someone registers online -for example- using an HTML form, the information is sent from the form to the database using a combination of HTML and PHP. Again, this is not possible with HTML or JavaScript alone because these scripts can't send data to the server.
* Include Function: PHP commands have an "include()" function that provides the ability to reuse PHP code anywhere. This valuable feature allows the programmer to reuse -for example- a menu on more than one web page. This reduces programming time by allowing you to change the menu code on all the web page by changing only the include() file.