Quantcast

Jump to content

Welcome to GameOn365
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. If you already have an account, login here - otherwise create an account for free today!

jason

jason

Member Since 21 Mar 2011
Offline Last Active Private
-----

Basic PHP

21 March 2011 - 09:00 PM

Always start php files/scripts with <?php and end them with ?>.You may also use <? to open them but it's not recommended. I only do it to keep this tutorial shorter and quicker to write.


*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

?>