[Tutorial] PHP Intro menu

User Tag List

Results 1 to 6 of 6
  1. #1
    Tanax's Avatar Active Member
    Reputation
    53
    Join Date
    Jan 2007
    Posts
    239
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [Tutorial] PHP Intro

    An introduction to PHP
    What is so great about PHP? What can you do with it, and how does it work? Read this tutorial to begin learning PHP.

    Hello!

    This is an introduction to PHP and how some basic things work.

    First, php is a server-side scripting language, which means that everything you script in php is processed by the server, before it goes out on the page. If you look on a .php website, and check the sourcecode, you'll see that there's only HTML there. Well, that's just because the server already processed all the php in the script, and echoed out the things that the scripter wanted the script to echo out.

    If you define a variable in a php-script, and put up the script on a website, there is no way to actually see the variable in the sourcecode, unless they get the .php file from the webhotel.

    So what does that mean? It means for example, that you can make simple login system that are still very secure.


    PHP Code:
    <?php

    ?>
    These are the opening tags that tells the server, "Wait, now it's php. Ahh! We have to process it!".
    Also, I might add that to actually test php scripts, you will need a webserver of some kind. If it's hosted on your computer, or on a webhotel doesn't matter as long as it has php installed.

    Variables:
    So, I mentioned variables before, what are they?

    Variables are kinda like a storage. You can add a value to a variable, and it will forever hold that value throughout the script. Let's take a simple example.

    Note: I'm not gonna write the php opening tags in all the examples, but in order for the script to actually work, they have to be there around everything.

    PHP Code:
    echo 'Hello world'
    So what did we do there? Well, I told the server that I wanted it to write that out on the page. Everything you "echo" out, is written on the page, like in regular HTML. If we were to check the sourcecode on that page with that code, it would only be "Hello world" because the other things were processed by the server.

    Back to variables. Variables are defined with a $-sign before the name of the variable. That way the server knows it's a variable, the name doesn't really matter.

    But with names it's important to know, that you cannot start a variablename with a number.
    And why would we need variables you ask?
    PHP Code:
    $hello1 'Hello world';
    $hello2 'Hi there!';

    echo 
    $hello1;
    echo 
    '<br />';
    echo 
    $hellor2
    Whoa! Now alot of stuff happend there!
    First off, we created 2 variables, called hello1, and hello2. We assigned different values to those. The first one got the value "Hello world", and the second one got "Hi there!".

    After that, we simply echoed those out on the page. This code would generate this:

    Hello world
    Hi there!

    Pretty basic script, doesn't really fill any function. But it's important that you understand the meaning of variables.

    PHP Tips: A variable is also known as a "var".

    And here's a more advanced example of the usage of variables:
    PHP Code:
    $var1 'Tanax';
    $var2 18// <-- Note that we don't have to use ' around numbers, because that value is not a string, it's an integer. Also, comments are defined with 2 slashes.
    $var3 'Sweden';

    echo 
    'Hello, my name is ' $var1 ', I am ' $var2 ' years old, and I live in ' $var3
    I'm pretty sure you understood the part where I defined the variables and assigned the values. But did you get the hang of the echoing out part?

    Let's take a look.
    First, this is a string. A string is a.. phrase. It can contain numbers, but it cannot ONLY be a number, because that is an integer.

    So what's with the dots? Well, if you're going to echo out variables inside a string, in the same echo, you have to do it like that.

    'string ' . var . ' string';
    If we have strings on both sides, we have to have dots on both sides.

    'string ' . var;
    If we have a string on only one side, we only need one dot, and also, you can end the echo right there after the var.

    var . ' string';
    Pretty self-explenational.

    If you tried this at home now, and you wrote something else than me, you might've gotten error messages. You see, if you write a ' inside a string, it ends the string.

    PHP Code:
    echo 'Hello, I'm 18 years old so you're not old enough'
    This wouldn't work. I'm using ' inside the string(you're and I'm), and that means that the string ends, and I have to use a ; after a string ends. Which I'm not after you'.
    So how do we get around this?

    Well, you have to escape them.
    PHP Code:
    echo 'Hello, I\'m 18 years old so you\'re not old enough'
    This would work.
    And this was the end of this intro lesson to php.

    We've discussed the usage of variables, and how to echo out things on a page.

    [Tutorial] PHP Intro
  2. #2
    nfs12's Avatar Member
    Reputation
    1
    Join Date
    Jul 2007
    Posts
    53
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nice guide +rep

  3. #3
    Tanax's Avatar Active Member
    Reputation
    53
    Join Date
    Jan 2007
    Posts
    239
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by nfs12 View Post
    nice guide +rep
    Thanks! Check out my other guide about pagination class
    Hm.

  4. #4
    Chenquie's Avatar Banned
    Reputation
    110
    Join Date
    Dec 2007
    Posts
    910
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Haha I've seen this before on a swedish site. You've just translated it.

  5. #5
    Tanax's Avatar Active Member
    Reputation
    53
    Join Date
    Jan 2007
    Posts
    239
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Neelz View Post
    Haha I've seen this before on a swedish site. You've just translated it.
    Erh, no.. I wrote this guide 100% myself.
    I've even put it up on another site of my own:

    Tanax’s Blog » PHP: Intro

    And I've listed it on pixel2life.com.

    Perhaps it's because alot of people have made a php intro tutorial??
    Hm.

  6. #6
    Chenquie's Avatar Banned
    Reputation
    110
    Join Date
    Dec 2007
    Posts
    910
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My bad then. But the example was all the same.

Similar Threads

  1. [Tutorial] PHP Pagination class
    By Tanax in forum Programming
    Replies: 5
    Last Post: 09-01-2015, 04:50 AM
  2. PHP Tutorial Glob()
    By Tanax in forum Programming
    Replies: 4
    Last Post: 05-12-2010, 05:14 PM
  3. [Tutorial] Extreme guide in php
    By Promthian in forum Programming
    Replies: 8
    Last Post: 09-28-2008, 07:08 PM
  4. Replies: 1
    Last Post: 04-23-2008, 02:15 PM
  5. [TuT/Guide] PHP Guide/Tutorial
    By Krilio in forum Programming
    Replies: 9
    Last Post: 04-11-2008, 10:00 AM
All times are GMT -5. The time now is 03:34 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search