My First PHP Tutorial - Beginning PHP

In order to really get back to basics and almost learn PHP from scratch again in order to get back into the mindset of a beginner who wants to learn PHP because of an interest I decided rather than most beginners guides which assume programming knowledge or experience I am going to assume none. This way even the most beginner of programmers can hopefully find this tutorial helpful in their quest to better themselves in the future, for this guide your going to need:

In order to really get back to basics and almost learn PHP from scratch again in order to get back into the mindset of a beginner who wants to learn PHP because of an interest I decided rather than most beginners guides which assume programming knowledge or experience I am going to assume none. This way even the most beginner of programmers can hopefully find this tutorial helpful in their quest to better themselves in the future, for this guide your going to need:

  • An editor of your choice - Dreamweaver (expensive), VIM (free) or Netbeans
  • A server to run your PHP on. (If you are unsure what this is - click HERE for a video tutorial on setting up your own local server to test on)
  • A willingness to learn PHP.

Step 1:

You need to open your editor, and goto create a new file. On all of the above suites you are looking for File -> New alternatively you can simultaneously press ctrl + N (once) and that will supply the prompt for creating a new file. Remember to select the type of file you want is a PHP file. You will be presented with a blank screen.

NB: At this point if you are using Dreamweaver, ensure you are in the 'code mode' and that you delete all of the pre-populated code that Dreamweaver has inserted to help you.

Step 2:

Now you are presented with an empty screen which looks like a complicated version of notepad, in order for any PHP code to work, you will need to open and close the PHP tags which look like this:

  1. <?PHP
  2. ?>

I have highlighted these lined in the same way Dreamweaver would, so don't worry if your page doesn't look 100% the same, however on line 1 you should currently have <?PHP and on line 2 you should have ?> You have now created your first PHP file, it does not do anything as of yet, but at this point it is wise to save it.

NB: If you are using a local development server such as WAMP or XAMPP then do not forget to save this file in the www directory for the server you are using, otherwise contact your hosting company if you are unsure how to get your file uploaded and saved in the correct area in order to view it in the future.

Step 3:

Lets make this file actually do something, the exciting bit! Believe it or not, getting this far was the hard part and now your here it is ONLY one line of code you need in order to give the viewers of your PHP page a nice welcoming message, simply amend your code so it looks like this:

  1. <?PHP
  2. echo 'Hello world!';
  3. ?>

 Now you will notice there is some things here which need to be explained, echo is a PHP command which outputs a string of characters into the page and the user will only every see Hello world! and nothing else, the '' marks are necessary to tell PHP that there isn't any functions or commands in the area between them so it doesn't get confused, and the ; (semicolon) is necessary to end the line of code else PHP won't know to stop looking for more parts to that particular line (you will see more reasoning behind this in the future when you use multiple lines of code)

 

Anyway, this is the end of this tutorial, I hope you found it useful - if you notice any bugs or have any suggestions please contact me!

 

PHP

Buy me a beer or a book?

amazon PayPal - The safer, easier way to donate online!

Free Downloads