Vectorials
Flash Perfection
3D Lessons
Tutorialkit
Markup Tutorials
Learn PHP
network
adv banner
Web Programming  Home Web Programming PHP PHP Introduction
rss

PHP Introduction

Author: Dan More by this author


PHP IntroductionPHP stands for PHP: Hypertext Preprocessor. PHP is an HTML-embedded scripting language. Much of its syntax is borrowed from C, Java and Perl with a couple of unique PHP-specific features thrown in. The goal of the language is to allow web developers to write dynamically generated pages quickly.

PHP files have the extension .php. Only very, very few web hosts do not support PHP, even most Windows hosts support it!

We enclose PHP code inside these tags:

<?PHP ?>

Remember this for later, ok?

We use variables to hold information.

We can set variables like this:

$variable_name = 'Will has so much gay love for Dan.';

We can then use them later within another variable or a function. A function does pretty much what it says on the tin.

Let's use the most basic function, echo.

echo "Hello Avengex Users!";

This will output: Hello Avengex Users!

You can also echo variables like this...

$lovers = 'Dan and Will forever.';
echo $lovers;

...or use them like this:

$who = 'Avengex Users!';
echo "Hello $who";

As you have probably noticed by now, each time you set a variable or use a function, you must end that line with a semi-colon. (;)

Next, let's do some simple calculations.

We use these basic mathematical operators:

+ for addition.
- for subtraction.
* for multiplication.
/ for division.

Let's try it:

$sum = 1 + 1;
echo $sum;

Fancy going a bit more advanced?

$sum = 5 * 42 + 10;
echo $sum;

What to do? Use an if/else statement!

We can use if/else statements to make decisions in PHP, and do certain things depending on the answer.

Here's an example:

$weather = "sunny";

if($weather == "sunny"){
echo "Looks like it's going to be a nice day today!";
} else {
echo "It's not going to be sunny today!";
}

PHP checks to see if what is contained inside the brackets is correct/true. If it is, it executes what's inside the first set of curly braces. If it is wrong/false, it skips to the else part, and executes what is inside the latter curly braces.

Full example.

Just to show you what it looks like when it's all pieced together.

<?PHP

$maths = "fun";

if($maths == "fun"){
$sum = 4156 + 5498;
echo "4156 and 5498 added together equals $sum!";
} else {
echo "Maths sucks.";
}

?>

Kthxbye.

Hope you learnt something from this random waffle. I'm going to go indulge myself in chocolate now. Thanks for reading and let me know what you think, any improvements or suggestions?

Feel free to PM me or email me if you have any questions, and don't forget to check out the PHP site at www.php.net for lots of info.



Author's URL: www.avengex.com

Rate this Material: Bad 1 2 3 4 5 Excellent
print this page tell a friend subscribe to newsletter subscribe to rss

Add comments to "PHP Introduction"