Post by Gamoc on Jul 12, 2007 22:53:21 GMT -5
Well, I decided to write a tutorial on some of the basics of PHP. It really is a fun language, and it can be very flexible. One of my favorite things about PHP is that you can put it directly into the HTML instead of implementing the HTML in like you would other languages.
Let's start with opening and closing a PHP statement.
To open one, you would put <?php, then, at the end, you would put ?>.
Now, let me show you what tha tlooks like.
Isn't that easy.
Now, let's get onto some other stuff.
You probably want to know how to write stuff out onto a page using PHP, well, it is not the same as javascript. You have to use the echo function. I goes like this.
It looks very each, well, it isn't, ha, just kidding. YOu just need to remember to put the semicolon at the end and surround the text in double quotes.
Now, let's get onto some better stuff, variables. There are two different ways to do variables, with letters and numbers.
Now, for the first thing, to start a variable, you have to use a $. Then you put the name of the variable, then, the value, that may be confusing, so let me show you.
With variables, like most other things, you have to end it with a semicolon, other words there will be an error.
Now, there are also the number variables, which go like this.
Isn't it self explanatory, yeah, I thought so.
Now, I shall show you how to use a variable in code.
See, with variables, you do not surround them with double quotes in the echo function. Let me show what it looks like in the middle of the sentence. You have to put a period after the variable for it to work also.
See, you have to make the spaces yourself in the sentences or in the variable. It is really simple. You have to put periods around variables like we did before.
Now, let's try making a sentence of variables.
See, you have to make the space between them.
Okay, the last thing I will tell you about is comments. Comments are just little tidbits of information that makes your code easier to read. The browser completely ignores comments, okay, well, let me show you how to make one.
We're going to start with a 1 line comment, the syntax is just two double slashes followed by the comment, like this.
// comment
Now, let's see that in some code.
Okay, the other kind of comment is the multi-lined comment. It looks like this.
/* This
is a
comment*/
Now, lets see that in some code
Those are just a couple of the most basic things that I thought I would share here.
Copyright ©
Let's start with opening and closing a PHP statement.
To open one, you would put <?php, then, at the end, you would put ?>.
Now, let me show you what tha tlooks like.
<?php
...some code...
?>
Isn't that easy.
Now, let's get onto some other stuff.
You probably want to know how to write stuff out onto a page using PHP, well, it is not the same as javascript. You have to use the echo function. I goes like this.
<?php
echo "Text here";
?>
It looks very each, well, it isn't, ha, just kidding. YOu just need to remember to put the semicolon at the end and surround the text in double quotes.
Now, let's get onto some better stuff, variables. There are two different ways to do variables, with letters and numbers.
Now, for the first thing, to start a variable, you have to use a $. Then you put the name of the variable, then, the value, that may be confusing, so let me show you.
<?php
$var_name="value";
?>
With variables, like most other things, you have to end it with a semicolon, other words there will be an error.
Now, there are also the number variables, which go like this.
<?php
$number=6;
?>
Isn't it self explanatory, yeah, I thought so.
Now, I shall show you how to use a variable in code.
<?php
$name="pikablu";
echo $name. "is the creator of this tutorial";
?>
See, with variables, you do not surround them with double quotes in the echo function. Let me show what it looks like in the middle of the sentence. You have to put a period after the variable for it to work also.
<?php
$name="pikablu";
echo "I am " . $name . " the creator of this guide.";
?>
See, you have to make the spaces yourself in the sentences or in the variable. It is really simple. You have to put periods around variables like we did before.
Now, let's try making a sentence of variables.
<?php
$hello="hello";
$world="world!";
echo $hello . " " . $world;
?>
See, you have to make the space between them.
Okay, the last thing I will tell you about is comments. Comments are just little tidbits of information that makes your code easier to read. The browser completely ignores comments, okay, well, let me show you how to make one.
We're going to start with a 1 line comment, the syntax is just two double slashes followed by the comment, like this.
// comment
Now, let's see that in some code.
<?php
// This is a comment
?>
Okay, the other kind of comment is the multi-lined comment. It looks like this.
/* This
is a
comment*/
Now, lets see that in some code
<?php
/*This is a comment.
Yes it is. */
?>
Those are just a couple of the most basic things that I thought I would share here.
Copyright ©
[blue]-Pikablu-[/blue]