PHP Programming
Introduction to Scripting
Wtf?
PHP is a server-side scripting language. Code for PHP web applications are stored on a web server in specially named files (.php typically). When users request the files via their browser (using that specific URL) the server PARSES the file looking for code to execute and executes it if it can. After execution, any resultant output (in the form of HTML) is sent to the client browser window as the web page the client requested.
This differs specifically from compiled languages like Lazarus(visual Pascal), C++ and so on in that the commands you write are not executed on your machine (the client "running" them) but rather on a capable server that must then communicate back to you the results of those commands. Compiled languages typically have their programs (executables and supporting data files) in a machine-ready form (often already translated into machine language like .exe files) ready to run on your local processor.
The model for programming web applications using PHP is different to other development, PHP is not a great language for capturing interactivity and is typically coupled with Javascript, Java and HTML in order to regain some of the "interactivity" typical of modern applications. This means that published PHP applications are typically a mixture of client side coding (javascript runs in the client browser) and server side scripting (PHP engine).
PHP is also often coupled with MySQL to make database-driven interactive "live" websites - you can learn more about this elsewhere in this resource
In this section you will learn some of the features of the PHP language, conventions and plenty to get you started. The web is full of great definitive references and tutorials for PHP. Consider this section as a starting point for your PHP investigations.
Some examples live to web
Code Structure
Files containing PHP commands MUST be named with the .php file extension to indicate to the SERVER that there is code to execute. The files themselves often contain HTML and PHP code intermingled and this gets confusing until you get your head around the notion of TAGS as ways of MARKING UP sections to do particular things.
A "typical" web page might have the following basic structure:
<html>
<head>
</head>
<body>
page contents go here
</body> </htm>
In the above example, the page contains pairs of tags as containers (eg. <head> ... </head>). Many HTML tags contain a beginning (<tag>) and end (</tag>) but not all. In general, VISIBLE web content occurs in the BODY of the web page.
We will develop "templates" that contain most of the code needed for a basic page so you do not have to worry too much about this, suffice to say the tags must be encoded correctly else the page will fail.
To place some PHP code in the BODY of the page, you create a "PHP container" thus:
<body>
<h1>Hello World</h1>
<?php
echo '<br>'.'Gidday Fred';
?>
</body>
In the above example, there is a Heading followed by the message "Gidday Fred". Notice the PHP container that has a start (<?php) and an end (?>) Everything between is considered CODE and will be executed by the SERVER before you see it. In the other sections we will learn more about what sorts of things you can get PHP to do.
A PHP web page can contain a mixture of HTML and PHP, and multiple PHP containers - so long as the begin-end tags for PHP containers do not overlap lots of variation is possible.
Related resources:
|