[Tutorial] Learn PHP Part 1
Php is a server side programing language used for making rich web applications.
Wordpress (Including http://pcmichiana.com/) use PHP.
To me, PHP is one of the easiest languages to learn the basics of quickly. Its syntax is easy to remember and simple.
Part 1a – Getting started
To start working with PHP, you will need some simple tools:
A text/code editor – Notepad will work but is VERY bad. Use something such as Notepad++
A webserver – You could buy hosting of a company, or install xamp on your computer. Great tutorial on installing it here.
A web browser – Ironic if you do not know what this is.
I will show you how to use either webservers as we go through this series.
Part1b – Setting up
If you are using xamp, go to your xamp folder (Defualt is C:/xamp/) and go into the htdocs folder. You will be putting all the PHP files in there.
If you have a paid host, just upload the PHP files to your host and open them with a browser. Just copy everything I do in the htdocs folder and upload it to your host.
Right click in the htdocs folder and go to New>File and name it ‘index.php’. When you go to your webserver, it will look for index.php as the homepage.
Open it with your editor and you are ready to go!
Part1c – Hello World!
We will create a simple script that will put the words ‘Hello World’ on the screen as a webpage. Very simple.
PHP is closely tied with HTML, so you can just put HTML around the php code.
To start any PHP file, we put
<?php
and at the end we put a
?>
You can put any HTML you want around those tags.
To print a word onto the screen, we use the print functions. Functions are a command to make the script do. By using the print function, we are telling the script to put something on the page.
The script will look like this:
<?php
print "Hello world!";
?>
To tell the print function to print ‘Hello world!’, we have to put it in speech marks.
The semi-colon at the end tell it that the print function is done.
Saving this as index.php in the htdocs folder of xamp and loading http://localhost/ should make the words ‘Hello world!’ appear. If you get a 404, then PHP is not installed.
That is it for this tutorial, I will continue next time with variables.