Publishing System Settings Logout Login Register
Intro to PHP part one
TutorialCommentsThe AuthorReport Tutorial
Tutorial Avatar
Rating
Add to Favorites
Posted on November 2nd, 2007
1100 views
PHP Coding
Hi!

I'm Friiks, the owner of this site and I'm going to teach you some basics of php.

First off PHP stands for PHP: Hypertext Preprocessor.
It's a server side scripting...like ASP and it's scripts are executed on the server.
It's similar to PERL and C so if you know any of them it will be way easier for you to learn PHP.

This tutorial will require:
* Text editor like notepad.
* Server that can run PHP files (PHP Installed).

Well enough talking - lets start!

[1] Echoing (outputting) information.

Lets learn how to actually output something!

Open up your text editor and create a blank file. I called it first.php (Be sure to make the extension .php).

Ok, that wasn't hard, wasn't it?
Now put type
<?php

in first and
?>
in second lines of your file.
Scripting block always starts with <?php and ends with ?>. You can use <? and ?> as well but I recommend standard form [<?php]!

Now your document should look like this
<?php
?>

Now that you have that done put
echo "Hello World!";
in between the <?php and ?> tags!
The file should look like this.
<?php
echo "Hello World!";
?>

If so - upload your php file to the server and run it.
It should look like this.

[2] Variables in PHP.

Variables in PHP are defined with an $ in front of the variable name. Like this

$variable_name = "Hello World!";

Variable names can only contain alpha-numeric characters and underscores (a-Z, 0-9, and _ ).

You can echo variables like this

<?php
$variable = "Hello World!";
echo $variable;
?>


Try it out and see what it outputs!

Oh, yea, numbers are set like this

<?php
$variable = 2;
?>


Try combining two strings like this

<?php
$var_1 = "Hello";
$var_2 = "World!";

echo $var_1." ".$var_2;
?>


[3] If & Else statements

IF you're going to code PHP more then you'll notice how much if and else statements you will use.
If you have ever coded GML, for example, you'll notice it's not much different although you have to always use brackets.

Lets check if 2 numbers are equal!

<?php
$num1 = 1;
$num2 = 3;

if($num1 == $num2){
echo 'equal';
}else{
echo 'unequal';
}

if($num1 > $num2){
echo $num." is larger than ".$num2;
}else{
echo $num1." isn't larger than ".$num2;
}

?>


Put this into a file, upload it and see what it outputs! ;)

Oh and my last note!
= and == has difference in PHP.
= - Sets variable to a value given!
== - Checks if 2 values given are equal!

You can read more about operators here.

Well that's pretty much all for today [I'm ill and can't write anything good anymore] so wait for second part of the tutorial! :)
Dig this tutorial?
Thank the author by sending him a few P2L credits!

Send
Friiks

This author is too busy writing tutorials instead of writing a personal profile!
View Full Profile Add as Friend Send PM
Pixel2Life Home Advanced Search Search Tutorial Index Publish Tutorials Community Forums Web Hosting P2L On Facebook P2L On Twitter P2L Feeds Tutorial Index Publish Tutorials Community Forums Web Hosting P2L On Facebook P2L On Twitter P2L Feeds Pixel2life Homepage Submit a Tutorial Publish a Tutorial Join our Forums P2L Marketplace Advertise on P2L P2L Website Hosting Help and FAQ Topsites Link Exchange P2L RSS Feeds P2L Sitemap Contact Us Privacy Statement Legal P2L Facebook Fanpage Follow us on Twitter P2L Studios Portal P2L Website Hosting Back to Top