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

[TUT] PHP Basics

Nom Nom

Member
Reputation
0
Nom Nom's PHP Basics Tutorial

Reet. Welcome to this tutorial. I will be teaching you the basics of php.
Right, now to start.

Well, if you don't know what PHP is, it's basically dynamic HTML. I do recommend learning (X)HTML before learning PHP. It basically outputs everything into HTML. If someone tries to view source from a web browser of the PHP page, they can't see the PHP, only HTML. If you want more info, go to http://php.net for more info.

The way to save PHP files is .php
There are other ways, but that is the easiest to remember.

How to start a PHP file
The way to start and end PHP code is to type this

PHP:
<?php//start
//insert code here
?>//end

Now, you see that I put some slashes like, // . This is a comment. It is completely ignored in the code. It's just a way of reminding you or telling other people what it does if you're giving them code.

Now, onto how to output text.

How to output text.

PHP:
<?php
echo "Hai world."; // outputs Hai world.
?>

Right, echo is a keyword, basically it will output what you type in between the quotes. You can use double or single, I will explain the differences later on in the tutorial. On the end is a semi-colon. This is how we end each statement or most lines. You can also output (X)HTML like so

PHP:
<?php
echo "<b><u>Hai world.</u></b>";
?>

This will output Hai world. onto the page. So, yeah, echo outputs whatever is inside the quotes. Now onto variables.

Variables

A variable, is like algebra basically. It just holds a value. I'll show you.

PHP:
<?php
$var1 = 2; // An integer variable
$var2 = "Hai"; // A string variable
$var3 = true; // A boolean variable

Those are the three main types of variables. If you want more info on variables, click HERE.

You can also use echo to output variables.
PHP:
<?php
$int = 2;
$string = "Hai world.";

echo "$int"; // will output 2
echo "\n" // new line.
echo "$string"; // will output Hai world.
echo '$string'; // will output $string

Now to explain the difference between double and single quotes. Well, double quotes will output variable values and stuff but single quotes output literally what is typed in between them. You see that I put a \n. This is a newline, it works the same as <br />, just much easier.


Hmm, I think that's about it for this tutorial. Any questions or mistakes etc, just pm me or post in here. Good luck!
 

Nom Nom

Member
Reputation
0
Hmm, going to make a second tutorial if I ever get the time. School is annoying. xD
 
Top