Basic php

Write your "How To" regarding anything you are comfortable with and you feel it will help the forum members.

NOTE :: All threads started here will appear only after the approval from Administrator
Post Reply
iBye
Posts: 720
Joined: Mon Jan 29, 2007 1:39 pm

Basic php

Post by iBye »

PHP which stands for Hypertext Preprocessor is one of the most used programming languages in the world. You need to know some basic HTML since PHP is just for the functions and you cant make layouts with it.

Why dont we go through some of the basic things of php.

First we look at Strings

Now, what the heck is a string?

It can be described with one word "sentence". A string is basically just like a sentence.
<?php
$string = 'abcdefghijklmnopqrstuvwxyz';
?>

Now lets look at this code. First we start with <?php, this is where the php code starts, this is required, otherwise your code will not work. ?> is the close tag.

Here is our string: $string = 'abcdefghijklmnopqrstuvwxyz';

The ' symbols are to tell the program the things inside are the the string value. The ; are the end symbol so the program knows the command ends there.

This string contains the alphabet as you can see, but it can also contain numbers.

Now, how do we get our string in the browser. Yes, now we gonna use the echo function. The echo function basically tells the browser what's in the string.
<?php
$string = 'abcdefghijklmnopqrstuvwxyz';
echo "$string";
?>

Now when you enter that page, you should see "abcdefghijklmnopqrstuvwxyz" on your screen. You can put 2 strings in, lets see how that looks.
<?php
$name = 'iBye';
$host = 'Smokyhosts';
echo "$string likes $host";
?>

That would echo out "iBye likes smokyhosts"

Note: You cannot use number in the string name, only letters.


Lets now look at if

The if function is what the name tells, if has 2 different terms "right" and "wrong" so it basically sends out the data based on if its right or wrong. Lets go and look at the example.
<?php
if (1 > 2)
echo "1 is bigger than 2";
?>

This code says "If 1 is larger than 2, echo 1 is bigger than 2" We all know that this is wrong. Lets first look at the symbol btw 1 and 2. "< means smaller than and > means larger than, you can also use plus, minus, devide and more.

So will not echo out anything since 1 is not larger than 2. If you change the < to > so the code tell "2 is larger than 1" the echo will be 1 is bigger than 2.

In that code, when it false there will be no echo. Lets see what we can do about that.
if (1 < 2){
echo "Your math is better than my!";
}
else {
echo "Haha, I suck on math";
}

This code is alittle bid harder, we need to use { to separate the echo's. Anyways, this code says "If 2 is larger than 1, echo: Your math is better than my!" But now, if its not echo: "Haha, I suck on math" The else function is what the name tells, if you dont do that, do this.

This is only some basic stuff, I am actually trying to get my php is shape. There are many online tutorials about this, but I would really recommend http://www.phpvideotutorials.com/. A guy is teacher out php in videos, really handy for those, like me who hate to read. Also check out php.net, everything about php and codes.

Some good editors for php, I am using jEdit /http://www.jedit.org/ and I have used Php designer / http://www.mpsoftware.dk/phpdesigner.php

Now, you cannot use these programs to view your finish code, you need a php server for that. I am using Easyphp / http://www.easyphp.org/ which is very easy to use. For those who are more experienced than me and you, they use Wamp / http://www.wampserver.com/.

This could be hard, but keep fighting. PHP is a real kill programming language and its really funny when you are testing and it works.

Thanks guys and keep the smokyhosts spirit up!


Tired of Newbies asking Questions? Tell them www.UseGoogleFFS.com
SHAdmin
Posts: 2089
Joined: Sat Dec 18, 2004 11:28 am
Contact:

Post by SHAdmin »

Nice intro for PHP there 'iBye'.

Your account has been credited with 25 points for sharing it.
Post Reply