Follow us on Twitter!
I'd prefer to die standing, than to live on my knees - Che Guevara
Wednesday, April 16, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 12
Guests Online: 12
Members Online: 0

Registered Members: 82800
Newest Member: santana1744
Latest Articles

Basic PHP

Arrow Image An intro to PHP...



An introduction to PHP by BobbyB.

This is my first ever article. Hope you like it.

I\'m going to cover some basics here - I\'m new to PHP as well so I\'m going to try and teach you some of what I have learnt.

First things first. PHP stands for Hypertext Preprocessor, and is a scripting language for the web. It can be placed anywhere in a page\'s source.
Now on to how to use it.

You can type your PHP scripts in notepad. When you save them, save them as \"whatyoulike.php\".
Make sure you have selected all files, and enclosed the name in double quotes. This prevents it as being saved as a txt file.

Here is a very simple PHP script. Since it is what most tutorials for most things do, this first PHP script will output \'Hello World\':

<?php
echo \"Hello World\";
?>

The tag tells the browser that it is no longer PHP.
The word \'echo\' is a command, and it outputs any text that follows it that is contained with in double quotes.
The semicolon tells the browser that the echo command is over.

So the script should output the text \'Hello World\'



Here is another script:

<?php
$content = \"Second script\";
echo $content;
?>

In this script, I have introduced variables. Basically, variables store data. The $ sign tells the browser that a variable introduced.
The text after the $ sign is the variable name. The = sign assigns anything after it to the variable.
The echo command then outputs the variable as text.

So the script should output the text \'Second script\'

In this script I have also introduced assignment operators. These are used to assign values to variables. THESE ARE IMPORTANT!
Here is a list of the full range:

= e.g. x=1 means x=1
+= e.g x+=1 means x=x+1
-= e.g. x-=1 means x=x-1
*= e.g. x*=1 means x=x*1
/= e.g. x/=1 means x=x/1
%= e.g. x%=1 means x=x%1 (x = the remainder of x/1)

NOTE: unlike most languages, variables in PHP do not have to have a variable type - any vaiable can contain any data.



Do you like these scripts? If so, lucky you. Here\'s another:
<?php
$numberx = 4;
$numbery = 8;
$total = $numberx+$numbery;
echo $numberx \" + \" $numbery \" = \" $total;
?>

This script creates 3 variables: numberx, numbery and total. numberx and numbery are added together to and this value is assigned to total.
Since numberx = 4 and numbery = 8, total = 12.
total is then echoed.

In this script I have introduced arithmetical operators. These are used to change mathematical data.
Here is a list of the full range:

+ (Addition)
- (Subtraction)
* (Multiplication)
/ (Division)
% (Modulous/Remainder of division)
++ (+1)
-- (-1)

Here are a few examples of how to use these:


$z = 4*2;
-------------
$z = 8


$z = 2;
$z++;
----------
$z = 3


$z = 4-2
-----------
$z = 2


$x = 6
$y = 4
$z = $x%$y
-----------------
$z = 2



For my final script, I am going to introduce loops, and I am going to demonstrate the IF loop. So, here\'s the script:

<?php
if (4>2)
echo \"Who loves BobbyB? Everyone loves BobbyB!\";
else
echo \"I hate BobbyB\";
?>

This last script uses the if loop to test if a statement is true. The statement is enclosed after the word if in brackets.
If the statement is true, the script will carry out the command the line below. If it is untrue however, the script will carry out the command after the else.
Since 4>2 is true, the script carries out the command after the if and echoes \"Who loves BobbyB? Everyone loves BobbyB!\". Which is also true.
The numbers could have been replaced with variables.

The \'is greater than sign\' > could have been repalced with any other comparison operator. These are:

== (is equal to)
!= (is not equal to)
> (is greater than)
< (is smaller than)
>= (is greater than or equal to)
<= (is smaller than or equal to)


That is the end of my tutorail. I hope I have outlined the basics of PHP for you. If you want to learn more, go to www.w3schools.com
It\'s where I learnt all of this.

Comments

nights_shadowon May 17 2005 - 12:54:44
Yeah, i was going to mention the open tag. But, very good article, especially for your first one!
BobbyBon May 17 2005 - 17:00:25
About that open tag - I think php fusion cuts it off for security reasons. I did on another site I posted it to.
MinoX1337on May 17 2005 - 20:25:12
<html> <body> <?php echo "Hello World"; ?> </body> </html> --------------------------------- <html> <body> <?php $content = "Second script"; echo $content; ?> </body> </html> Pfft
MinoX1337on May 17 2005 - 20:27:27
damn that messange go screwed :S here it is: lol http://whh.no-ip.com/lolla.txt
Zietlebenon July 21 2005 - 04:56:05
Very nice article good job i started learning php yesterday and already i feel that i have the hang of things. to me php is kinda a html ,javascript , & vb mix Pfft NICE JOB!!!
-The_Flash-on June 21 2006 - 02:42:42
I like this article, 9/10.
Thucydideson July 12 2006 - 22:41:36
A good intro article. I just want to point out a small error though, PHP stands for PHP: Hypertext Preprocessor and is thus a recursive acronym (actually, a recursive abbreviation in this case), sort of like GNU Not Unix as another example.
02nwoodon November 10 2006 - 09:30:16
For my final script, I am going to introduce loops, and I am going to demonstrate the IF loop. So, here's the script. IF ISN NOT A LOOP IF ISN NOT A LOOP IF ISN NOT A LOOP I SHALL GIVE AN EXAMPLE OF A LOOP IT IS NOT IF IT IS WHILE i dont think you mentioned this in the article but with some functions you need to put { } after the function to tell the function what code to execute. if is not a loop a while loop goes something like this $loop = "this code loops"; while (condition){ echo "loop: " .$loop ""; i am sorry but the if loop just qute basicly annoyed me thanks doskey
Post Comment

Sorry.

You must have completed the challenge Basic 1 and have 100 points or more, to be able to post.