*Note the semi-colon at the end of most lines.*
To print text simply use echo.
Example: This will write "Hello" to your screen.
<?
echo "Hello";
?>
Comments can be created by using //Comment here. Or if using multiple lines /* Comment here */.
To set a variable we use $.
$variable_name = "content here";
Example: This will also write "Hello" to your screen.
<?
$myvariable = "Hello";
echo $myvariable; //Echo the variable
?>
To echo multiple variables/strings without creating a new echo each time simply use a period.
Example: This will write "Hello and Welcome to my site."
<?
$myvar = "Welcome";
$var2 = "Hello";
echo $var2 . " and " . $myvar . " to my site.";
?>
If/Else statements. Take note of the curly braces!
Example:If number = 1 it will echo "The Number is 1", if it isn't it will echo "The number is not 1".
<?
$number = '2';
if($number == '1'){ //Curly Braces used for code to be executed
echo "The number is 1!";
} //Make sure Curly Braces are closed
else
{
echo "The number is NOT 1!";
}
?>
Functions. Functions must be called in order to be executed.
<?
function echo_text(){ //Our Function. Take note of curly braces.
echo "Hello Again";
echo "<br />"; //Line Break
echo "Bye!";
}
echo_text(); //Call to the function
?>