Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Page 1 of 2 12 LastLast
Results 1 to 10 of 19
  1. #1
    Join Date
    Aug 2004
    Location
    Sawley
    Posts
    771
    Tokens
    1,631
    Habbo
    T0X!C-uk

    Latest Awards:

    Default PHP Tutorial: Introduction to PHP

    Ok as request by people i have written a brief introduction to php which if read properly should get you on the road :p

    The tutorial has taken me just over 2 days to write so i hope you appriciate it. Would love Rep if you like it

    PHP - Syntax
    ----Syntax - The rules that must be followed to write properly structured code.

    PHP's syntax are similar to most other programming languages (C, Java, Perl) with the addition that all PHP code is contained with a tag, of sorts. All PHP code must be contained within the following...

    Code:
    <?php
    ?>
    
    or the shorthand PHP tag that requires shorthand support to be enabled on your server...
    
    <?
    ?>
    If you are writing PHP scripts and plan on distributing (Selling) them, I suggest that you use the standard form (which includes the ?php) rather than the shorthand form. This will ensure that your scripts will work, even when running on other servers with different settings.

    How to Save Your PHP Pages
    If you have PHP inside your HTML, and you want the web browser to display it correctly you must save the file as .php instead of .html. So be sure to check that you are saving your files correctly. Instead of index.html, it should be index.php if there is PHP inside included in the file.

    Example Simple HTML & PHP Page
    Below is an example of one of the easiest PHP and HTML page that you can create and still follow web standards.

    Code:
    <html>
    <head>
    <title>My First PHP Page</title>
    </head>
    <body>
    <?php
    echo "Hello Liam!";
    ?>
    </body>
    </html>
    If you save this file and place it on PHP enabled server then you should see "Hello Liam!" displayed. If not, please check that you followed my example correctly.

    I used the PHP function echo to write Hello World and we will be talking in greater depth about this PHP function and others, later on in this or later tutorials (If i get around to writing them :p).

    The Semicolon!
    As you may or may not have noticed in the above example, there was a semicolon after the line of PHP code. The semicolon is the end of a PHP statement and should never be forgotten. For example, if I repeated "Hello Liam!" several times, then I would need to place a semicolon at the end of each statement.

    White Space
    As with HTML, whitespace is ignored between lines of code. This means it is OK to have one line of PHP code, then 20 lines of blank space before the next line of PHP code.

    Example:
    Code:
    <html>
    <head>
    <title>My First PHP Page</title>
    </head>
    <body>
    <?php
    echo "Hello World!";
    
    
    
    
    
    
    
    
    echo "Hello World!";
    ?>
    </body>
    </html>
    [OK next is variables if you are not already lost then great continue to the next bit but if you require help with any of the above please PM me and i will help you the best i can.]

    PHP - Variables
    f you have never had any programming, Algebra, or scripting experience, then the concept of variables will be a new to you.

    A variable is a means of storing a value, such as text string "Hello World!" or the integer value 4. A variable can then be reused throughout your code, instead of having to type out the actual value, over and over again.
    In PHP you define a variable with the following form:

    $variable_name = Value;

    If you forget that dollar sign at the beginning, it will not work. This is a common mistake for new PHP programmers!

    A Quick Variable Example
    Say that we wanted to store the values that I talked about in the above paragraph. How would I go about doing this? We would first want to make a variable name and then set that equal to the value we want. See my example below for the correct way to do this.

    Code:
    <?php
    $hello = "Hello World!";
    $a_number = 4;
    ?>
    [As you may have noticed this is a long tutorial but is worth it :p. If you start to get bored dont forget this will always be here you can remember where you are then go out for a bit then come back. It is better to have breaks in between as it helps you to take more in ]

    PHP - Echo
    As you saw in the previous lesson, the PHP function echo is a means of outputting text to the web browser. Throughout your PHP career you will be using the echo function more than any other.

    Outputting a String
    To output a string use the PHP echo function. You can place either a string variable or you can use quotes, like I have done below, to create a string that the echo function will output.

    Code:
    <?php
    echo "Hello!";
    echo "<h5>I love Liam :p</h5>";
    ?>
    In the above example I output Hello! without a hitch. To review, this text we are outputting is being sent to the user as a web page, so it is important that we use proper HTML syntax!

    In the second line I used echo to write a valid Header 5 HTML statement! To do this I simply put the <h5> at the beginning of the string and closed it at the end of the string. Just because you're using PHP to make web pages does not mean you can forget about HTML syntax! HTML plays a big part in most PHP coding. For example Habboxforum May look like a snazzy php full vbulletin but if you have ever saw a vbulletin file you would see a great deal of HTML coding mixed with PHP.

    Be Careful When Echoing Quotes!
    It is pretty cool that you can output HTML with PHP. However, you must be careful when using HTML code or any other string that includes quotes! The echo function uses quotes to define the beginning and end of the string, so you must use one of the following tactics if your string contains quotations:

    * Don't use quotes inside your string
    * Escape your quotes that are within the string with a slash. To escape a quote just place a slash directly before the quotation mark, i.e. \"
    * Use single quotes (apostrophes) for quotes inside your string.

    See my example below for the right and wrong use of the echo function:

    Code:
    <?php
    echo "<h5 class="specialH5">I love Liam!</h5>";
    // This won't work because of the quotes around specialH5!
    
    echo "<h5 class=\"specialH5\">I love Liam!</h5>";
    // OK because we escaped the quotes!
    
    echo "<h5 class='specialH5'>I love Liam!</h5>";
    // OK because we used an apostrophe '.
    ?>
    Echoing Variables
    Echoing variables is easy. The PHP developers put in some extra work to make the common task of echoing all variables nearly foolproof! No quotations are required, even if the variable does not hold a string. Below is the correct format for echoing a variable.
    Code:
    <?php
    $my_string = "Hello HBF Members. My name is: ";
    $my_letter = Liam;
    echo $my_string;
    echo $my_letter;
    ?>
    OutPut:
    Code:
    Hello HBF Members. My name is:Liam
    Part 2 to this MASSIVE tutorial will be up sometime tomorrow. Getting late now and been working all day so i need some sleep :p

    Thanks for reading hope you learned something from this part

    Thread closed by ,Jess, (Forum Super Moderator): Due to bump.
    Last edited by ,Jess,; 03-11-2008 at 07:41 PM.

  2. #2
    Join Date
    Jan 2005
    Location
    Kentucky Fried Chicken
    Posts
    4,610
    Tokens
    0

    Latest Awards:

    Default

    GREAT!

    Mod Please Stick x]

  3. #3
    Join Date
    Oct 2004
    Location
    Scotland
    Posts
    2,280
    Tokens
    1,075

    Latest Awards:

    Default

    this needs stickied!!! AMAZING!!!

    http://www.stupidian.com
    (contains mild swearing)

  4. #4
    Join Date
    Nov 2004
    Location
    Stealth!
    Posts
    1,766
    Tokens
    0

    Latest Awards:

    Default

    Good tutorial, should be stickied!

  5. #5
    Join Date
    Nov 2004
    Location
    USA
    Posts
    903
    Tokens
    0

    Default

    honestly, i couldnt figure out wth you were talking about. i guess i'm not very computery :p
    This Account Is Rarely Used

  6. #6
    Join Date
    Jul 2004
    Location
    Webby Forums!
    Posts
    1,879
    Tokens
    0

    Latest Awards:

    Default

    good tut + rep should be stikied.


    Chilimagik.net // Reviews, Band Biographies, News, Pics + Loads More!!
    [Thybag.co.uk - Vive la revolutione]

  7. #7
    Join Date
    Jun 2005
    Posts
    4,795
    Tokens
    0

    Latest Awards:

    Default

    very very basic no gd for advanced users but v v gd for newbies to PHP. Well done!

  8. #8
    Join Date
    Jul 2004
    Location
    Webby Forums!
    Posts
    1,879
    Tokens
    0

    Latest Awards:

    Default

    Proably why its called an introduction to php.


    Chilimagik.net // Reviews, Band Biographies, News, Pics + Loads More!!
    [Thybag.co.uk - Vive la revolutione]

  9. #9
    Join Date
    Aug 2004
    Location
    Sawley
    Posts
    771
    Tokens
    1,631
    Habbo
    T0X!C-uk

    Latest Awards:

    Default

    Quote Originally Posted by splintercell!
    Proably why its called an introduction to php.
    Exactly :p

  10. #10
    Join Date
    Jan 2006
    Posts
    33
    Tokens
    0

    Default

    Nice tutorial dude

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •