A Beginner's Guide to Php [Tutorial 1]

Discussion in 'Web Programming' started by beast217, Jul 22, 2009.

A Beginner's Guide to Php [Tutorial 1]
  1. Unread #1 - Jul 22, 2009 at 10:49 AM
  2. beast217
    Joined:
    Jul 22, 2009
    Posts:
    9
    Referrals:
    0
    Sythe Gold:
    0

    beast217 Newcomer

    A Beginner's Guide to Php [Tutorial 1]

    Hi everyone.

    This is the first of many tutorials to come, with the aim of teaching the average beginner php.


    Okay... so lets get started.

    What is php?

    Php is a web based programming language used for many, many functions.

    To use php offline ( without uploading it to a php enabled server) you need to download a program called "WAMP", for windows, or "MAMP" for Mac. You can find both of them very quickly on google, and they are both free. Once you have it installed, all you need to do is open wamp, right click on the small icon in the windows toolbar, and click "Go Online". In your favourite internet browser, simply type "localhost" and you should get to the WAMP page.

    Open up C:/wamp/www/ and you will find your projects. Right now you dont have any, so create folder called "Tutorial 1". Save all the files you create from this tutorial into this folder. If you navigate to localhost in your internet browser, you should see "Tutorial 1" under the projects list.

    To start, open up your favourite text editor, mine being Notepad ++. The text editor should have line number's next to the text, and since Notepad ++ is free, i use it. Just google it, you should get it quickly.

    Now, im not going to teach you html, because this is not "A beginners guide to html". Html might be necessary in some parts of the following tutorials, so if you dont have a basic understanding of html, i suggest you click here to learn it.

    As with html, and most web-based languages, the source code has to start with an opening and closing tag, to tell the web browser what language you are writing in. For php, it's the following:


    Code:
    <?php
    
    /* Code goes here
    Code goes here
    Code goes here
    Code goes here
    Code goes here*/
    
    ?>

    So as you can see from the above, <?php is the opening tag, ?> is the closing tag, and anything that goes in between the two tags is php code.

    The next part we will look at is echo and print. They are different, but for your level of programming, you can assume they are the same.

    Have a look at the following code:

    Code:
    <?php
    
    echo "It works";
    
    ?>

    Notice 3 things about the above code:
    -echo = this means to display the following.
    -" " = the two " have to be used whenever you echo out something.
    -;= the ; has to be placed at the end of each statement, otherwise you will be given an error.

    So type the php code up into your text editor, and save it as "index.php" in your "tutorial 1" folder.

    Navigate to localhost in your internet browser, click on "Tutorial 1" and you should see the following:

    Tutorial 1 on my site.

    Note: You can replace "echo" with "print"; it will do the same thing at this stage.

    Ok i think thats enough for today. I hope you enjoyed it, and i will try write my next tutorial tomorrow.
     
< A Beginner's Guide to Php [Tutorial 2] | Anyone Know A Free Web Host With 99.9 Uptime? >

Users viewing this thread
1 guest


 
 
Adblock breaks this site