Created by: Dr.Ferrous
PHP is an open source, server-side web-scripting language that is compatible with all the major web servers (most notably Apache) and databases.
By the help of PHP code you can create dynamic website content. Dynamic Web sites are flexible applications than merely sites.
If you know HTML, but you have no experience in the field of programming, you can easily learn PHP and MySQL with the help of this course.
This course starts from the most simple, explaining the operations of the PHP language, and then move on to detail how to create PHP programs, how to load the PHP scripts, and to the final approach more complex items, such as SQL commands, working with MySQL database, using classes and OOP (Object Oriented Programming) in PHP.
In order to run PHP, you need a server, because PHP is a server-sided scripting language, you either have to get some web space with a hosting company that supports PHP, or make your computer pretend that it has a server installed.
This is because PHP is not run on your PC - it's executed on the server. The results are then sent back to the client PC (your computer).
First, you need to download the software. You can get it from here: http://www.wampserver.com
You have now downloaded and installed Wampserver. This will give you a server on your own PC (Windows users).
If the installation went well, you should have an new icon in the bottom right, where the clock is:
Every PHP script contains two special lines (or PHP tags) that indicate to PHP server that the text contained between the two tags must be parsed as PHP instructions. Between these two lines will be written the PHP code.
To start writing a PHP script, open your text editor (Notepad++, Brackets, Sublime Text, Atom.io...) and insert these two lines:
This is a start code and displays nothing.
You can save your script (with ANSI or UTF-8 format) in a text file with the ".php" extension, in the
"www" (for WampServer) folder, with a name that respect the following rules:
Your saved PHP files should be in this folder (usually
PHP scripts execute three basic operations:
Let`s write a simple PHP script that displays a text in the browser window. Open your text editor and add the fallowing code:
Save the file with a name with the ".php" extension (for example
"index.php"), in the proper directory of your Web server (
To see the result, access in the browser the fallowing address:
If everything is made correctly, the browser will displays "Hello World!".
Notice that the instruction begins with a word "echo" and ends with a semicolon (;).
Each code line in PHP must end with a semicolon (;), it is used to distinguish one set of instructions from another.
The "echo" statement sends output data to be displayed in the browser (There are two basic statements to output text with PHP: echo and print.).
Single (or double) quotes are used to delimit strings (a text expression), in our case 'Hello World!'.
here is another PHP script that outputs a HTML code and it's placed inside a HTML document:
A secondary but still important aspect to any programming is documenting your code.
In PHP, you can use // to make a single-line comment or /* and */ for multiline comment block.