• home
  • forum
  • my
  • kt
  • download
  • Basic PHP Tutorial - Learn the basics

    Author: 2008-08-23 13:32:55 From:

    Well lets first start with the question what is php? Well I can't explain that pretty good so here's a explanation from Wikipedia.

    Now lets start with the actual tutorial. First we'll have it about the basic syntax for variables and other things.
    In PHp you can have different types of variables: array's, strings, integers, etc...
    Here's an example for an array, string and integer:

    <php
    $string="string"; //string type 1
    $string='string'; //string type 2
    $integer=5; // integer
    $array_arr=array(); //array
    ?>

    You see that I use two types of enclosing for strings. I prefer the '' because then you can easily enclose html tags in the variable if you have to.

    Now let's go on to our first mini-script. A basic "hello world" script. We'll present hello world in 7 different sizes on the screen. It'll be like this:

    Hello world!
    Hello world!

    Hello world!

    Hello world!

    Hello world!

    Hello world!


    I'll first give the code and then I'll explain it bit by bit.

    <php
    for($i=6; $i>0; $i--){
    echo "<h" . $i . ">Hello world!</h" . $i . "><br />";
    }
    ?>

    Now let me explain the code.
    First the for-loop:

    for($i=6; $i>0; $i--){

    and we say in the loop it has to stay above 0.
    Then we put

    $i--

    what means that for every loop the for-loop does the variable $i goes down by one.
    Now part two of our code:

    echo "<h" . $i . ">Hello world!</h" . $i . "><br />";


    In this part we are echoing the different headerstyles with the text "Hello world!".
    It'll have 6 different sizes.
    The end of all code is done with a single bracket and the php closing tag:

    }?>

    In my next tutorial I'll explain the basics from security, loops, $_POST and $_GET.

    discuss this topic to forum

    relation tutorial

    No relevant information

    Category

      Ad Management (4)
      Calendars (3)
      Chat Systems (7)
      Content Management (6)
      Cookies and Sessions (8)
      Counters (8)
      Database Related (8)
      Date and Time (9)
      Development (6)
      Discussion Boards (7)
      E Commerce (6)
      Email Systems (9)
      Error Handling (5)
      File Manipulation (10)
      Flash and PHP (4)
      Form Processing (7)
      Guestbooks (8)
      Image Manipulation (3)
      Installing PHP (5)
      Introduction to PHP (23)
      Link Indexing (8)
      Mailing List Management (9)
      Miscellaneous (54)
      Networking (8)
      News Publishing (9)
      OOP (24)
      PEAR (6)
      PHP vs Other Languages (2)
      Polls and Voting (6)
      Postcards (1)
      Randomizing (14)
      Redirection (11)
      Searching (9)
      Security (29)
      Site Navigation (16)
      User Authentication (14)
      WAP and WML (7)
      Web Fetching (8)
      Web Traffic Analysis (15)
      XML and PHP (16)

    New

    Hot