Help - Search - Members - Calendar
Full Version: [php] - The Basics
Pixel2Life Forum > Member Tutorials and Requests > Forum Tutorial Archives > PHP Tutorials
Kev
Well I'm not going to go in depth in this tutorial but I will show you the basics.
FIRST : Opening tag
CODE
<?php
this tag opens a php document, it tells the browser that when it reaches that string start reading as php. An alternative is [code[<?[/code] however some older php versions don't accept this and read is as a string of text. So it's safer to use
CODE
<?php
.

Ending tag
--------
Next is the ending tag.
CODE
?>
simple eh? That tells the browser to stop reading it as PHP code.

Variables
--------
A variable in PHP is just like a variable in Algebra (if you don't know Algebra it doesnt matter)
It has a value.
CODE
$variable=papa
that is an example of a variable, it assigns $variable the value papa. An example of how you could use this is
CODE
<?php
$variable=papa;
echo '$variable';
?>

That would echo the word papa on the page, notice after every php statement I put a ';' this is important as it tells the browser to end that statement.

Echo
-----
Notice in the above example I used 'echo', echo is a php function that "echos" something, in other words display it. you might see sometimes 'print', it is the same thing, how you use it is basically a matter of preference.

That concludes this tutorial, maybe later I might write a bit more indepth tutorial covering functions, mysql integration, and other things. Thanks.


this tutorial was made by someone on my staff. for more please visit www.kev-designs.com
meadow
Cheers, I can't do too much php at the moment becuase ym server is being a bit odd.
MaRmAR
OK.
1) $variable=papa; should be $variable="papa";
2) echo '$variable'; should be echo "$variable"; because with apostrofes it wouldn't print real value of $variable but only "$variable" (but we want "papa")..
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.