PHP Basics
Submission Date: 2005-08-18
Website:
Email:
Keywords: Keywords Unavailable
Synopsis: Learn the basics of PHP. PHP Basics
Introduction
Welcome to part 1 of a series of php tutorials by me! In this tutorial, i will teach you how to make a basic php program.. Mainly how to print output from a php script... I hope you will enjoy using PHP as much as i have, and that you will NEVER use ASP again (if you ever have)..
OK, lets start! You can add php to any html page, most servers only run PHP in .php, .php3 or .phtml files, not many run in .html files. A simple example of a PHP script is as follows:
<html>
<body>
A simple HTML page with php embeded!!!
<p>
<?php
// This is PHP
/* These are both comments
:) */
?>
</body>
</html>
From that we have learnt that php scripts are placed between tags, (sometimes for the starting tag)... Secondly we have learnt that "//" starts a single line comment, and that /* starts a multi-line comment, with */ as a closing multi-line comment..
Basic PHP Functions
The most basic php function would be the "print" function! usage as follows:
<?php
print \"Hello World\";
?>
Which prints the string "Hello World" into the HTML document!
Other basics include if statments:
if ($x==1) { // if x equals 1 then run this :o }
and while:
while ($x==1) { // while x is still equal to 1 , run! }
Will run forever - as $x is always 1!
One more for now, for:
for ($i=0;$i<100;$i++) {
print "We are $i
";
}
Will print "We are " then the nth time its dont it (minus 1 cus it starts from 0) like:
We are 0 We are 1 We are 2 ... We are 99
Your First PHP Program!
Here it is:
<html>
<body>
<?php
print \"Hello World!<p>\";
for ($i=1;$i<=50;$i++) {
print \"I AM $i!<br>\";
}
print \"I AM 1-50!!!<p><hr>\";
?>
</body>
</html>
Will print "Hello World" then a paragraph then "I AM n" (n=1 to 5) then "I AM 1-50" then a paragraph then an
!
Please check back in a while to get the next one!!!
Bye!
Theo
Link to this article:
http://www.daremedy.com/tutorials/php/tut-1124403939.html
