CODE
<script LANGUAGE="PHP">
CODE
<?PHP
CODE
<?
After you have done that, you can start writing in PHP. The first function that you will learn is echo().
Echo() will output a string of text that you specify. Here is an example:
CODE
<?PHP
echo("Hello World!");
PHP?>
echo("Hello World!");
PHP?>
Each line of code in PHP ends with a semicolon (
Another way you can do the same thing is like this:
CODE
<?PHP
$thisisavariable = "Hello World!";
echo("$thisisavariable");
PHP?>
$thisisavariable = "Hello World!";
echo("$thisisavariable");
PHP?>
$thisisavariable is a variable. All variables have a dollar sign ($) before them. Variables can also contain numbers, as shown below.
CODE
<?PHP
$var = 123;
PHP?>
$var = 123;
PHP?>
Comments can be shown in PHP also, they are placed after semicolons and have "//" before them.
CODE
<?PHP
$var = 123; // Put the number 123 in the variable $var.
PHP?>
$var = 123; // Put the number 123 in the variable $var.
PHP?>
Below is an example of what you can do with PHP. It will be commented so you can follow along.
This is how it works:
Check to see if the user has specified their name. If not, display a form so they can enter there name. If they have entered there name print "Hello, (user's name here)!".
CODE
<?PHP //Tell the server that to process the PHP.
if ($_GET['name'] <> "") //If statements do not need semicolons.
{ //This just means this is where the code for the if statement starts.
// This code is run if they have specified their name. The <> means not equal.
$user_name = $_GET['name']; //Put the user's name is $user_name.
echo("Hello, $user_name");
}
else // This means that the user did not specify a name yet.
{
echo("Please type your name and press Submit:");
echo("<FORM ACTION='3.php' METHOD='GET'>");
//Notice I am using single quotes inside of echo. If you were to use double quotes you would crash your program.
echo("<INPUT TYPE='text' NAME='name' LENGTH='30'>");
echo("<INPUT TYPE='Submit' VALUE='Submit'>");
}
PHP?>
if ($_GET['name'] <> "") //If statements do not need semicolons.
{ //This just means this is where the code for the if statement starts.
// This code is run if they have specified their name. The <> means not equal.
$user_name = $_GET['name']; //Put the user's name is $user_name.
echo("Hello, $user_name");
}
else // This means that the user did not specify a name yet.
{
echo("Please type your name and press Submit:");
echo("<FORM ACTION='3.php' METHOD='GET'>");
//Notice I am using single quotes inside of echo. If you were to use double quotes you would crash your program.
echo("<INPUT TYPE='text' NAME='name' LENGTH='30'>");
echo("<INPUT TYPE='Submit' VALUE='Submit'>");
}
PHP?>
I really hoped this helps some people start to learn PHP. Any questions, comments or constructive critiscism (this is my first tutorial) can be posted and I will answer them. I'll post the links to the 3 examples (Hello World, Hello World (with a variable), and the example once I get enough credits to become active again

