• Welcome to ForumKorner!
    Join today and become a part of the community.

PHP Tutorials - 1 - The Basics

Sanctuary

User is banned.
Reputation
0
Hi there. This thread contains the basic things in the beginning process of learning PHP.



Part 1 - PHP Tags:
To start this lesson, you're going to need to make a .php file.
And of course, PHP has it's own tags to start and stop interpreting the code inside the file.
At the beginning and end of each file, you'll need these tags:

PHP:
<?php

?>

You can also use this, although I don't recommend it:
PHP:
<?

?>

These tags are vital. Similar to HTML's <!DOCTYPE html> tag, I guess you could say.




Part 2 - "Echo":
"echo" basically means display "x" onto the screen. Whenever you want to display something, you're going to need use the echo function.

So let's say you want to display the words "This is the internet." onto your screen.
This would be the code you would use:
PHP:
<?php

echo "This is the internet.";

?>

You would need to put your text inside quotation marks every time you use the echo function.
You may also notice that I added a semicolon after the quotation marks. Quotations mark are vital when writing PHP. For right now, it's not 100% necessary, but use it and keep it in mind.

Now, let's say you want to display something instead of words. You want to display the number 1337 onto your screen.
This would be the code you would use:
PHP:
<?php

echo 1337;

?>

Unlike regular text, number are not put in quotation marks. Remember that.




Part 3 - Variables:
In PHP, there are these things called 'Variables'. Variables take the place of something else. Kinda similar to the stuff you learned in algebra class.

To create a variable, you use the $ symbol.
Now, we can name our variable anything, anything at all.
We also need to create it's value. That basically means making it equal to something, like text or a number.

I'll give you an example with 2 variables.
PHP:
<?php

$text="echo statement #1";
$number=1337;

?>

So, you would type it like that. But if we were to save our file, nothing would display on the screen. Why? Because we haven't used 'echo' to display anything yet!
So, if you want to echo the variable $something, you would use this code:
PHP:
<?php

$text="echo statement";
$number=1337;

echo $text;

?>

If were to save our file like that, it would display "echo statement" on our screen (without the quotation marks).
But what if you to echo out the variable $anything ?
Simple. Just change the echo statement.
PHP:
<?php

$text="echo statement";
$number=1337;

echo $number;

?>

This would display the number 1337 on our screen.
But what if we wanted to combine our variables?
All you would need to do is echo out both variables, and combine them by using a period, like this:
PHP:
<?php

$text="echo statement";
$number=1337;

echo $text.$number;

?>

It would display "echo statement1337" (without the quotation marks).
Of course, you could add a space, or a line break if you wanted.
Anyways, I think that's about it for now. :)
Hope you found it useful, even though these are the basics of the basic stuff.

And before anyone says otherwise, no, this is not a "copy pasta". I typed this all myself. If you want, feel free to attempt to prove me wrong

- Sanctuary

inb4 Someone tells me I did something wrong
inb4 OP can't inb4

Original thread can be found by clicking here.
 

Kyles

User is banned.
Reputation
0
Very nice thread here, how many tutorial additions do you plan to add?
 

Sanctuary

User is banned.
Reputation
0
Kyle said:
Very nice thread here, how many tutorial additions do you plan to add?

I'll add them every now & then. Also depends on how long it takes to type out each lesson, cuz some things are harder to explain than others. :p

EDIT: 1337th post.
 

Kyles

User is banned.
Reputation
0
Okay. At a moment, if you make seperate threads and depending on how detailed they are. I'll merge them all and sticky.
 
Top