More Advanced PHP
1.0.)Simple outputs:
You can make a simple output with the use of an echo or print command. Here's an example:
<?php
echo “Hello World <br />”;
print “Hello again”;
?>
Type this text into notepad, and save it as Helloworld.php, then upload it onto a web server or on your localhost. Go to the page called Helloworld.php and you can see the output is like below:
Hello World
Hello again
As you can see you can use HTML code in your php scripts.
--------------------------------------------------------------------------------------------------------------
1.1.)Further information on Variables:
-Variable names must begin with the $ symbol
-there mustn't be a blank or blank space in the name
-the variable can not be named after a pre-existing command in php
-just can have letters and numbers (a - z) (0- 9) and underscores ( _ )
Example:
<?php
$a = “hello”;
$b = “world”;
echo $a;
echo “ “;
echo $b;
?>
The output will be hello world.
--------------------------------------------------------------------------------------------------------------
1.2.) Operators in PHP, operators in PHP do math and logic inside of a script such as addition, subtraction, greater then, less then, and more here is a table below to describe them.
You can make a simple output with the use of an echo or print command. Here's an example:
<?php
echo “Hello World <br />”;
print “Hello again”;
?>
Type this text into notepad, and save it as Helloworld.php, then upload it onto a web server or on your localhost. Go to the page called Helloworld.php and you can see the output is like below:
Hello World
Hello again
As you can see you can use HTML code in your php scripts.
--------------------------------------------------------------------------------------------------------------
1.1.)Further information on Variables:
-Variable names must begin with the $ symbol
-there mustn't be a blank or blank space in the name
-the variable can not be named after a pre-existing command in php
-just can have letters and numbers (a - z) (0- 9) and underscores ( _ )
Example:
<?php
$a = “hello”;
$b = “world”;
echo $a;
echo “ “;
echo $b;
?>
The output will be hello world.
--------------------------------------------------------------------------------------------------------------
1.2.) Operators in PHP, operators in PHP do math and logic inside of a script such as addition, subtraction, greater then, less then, and more here is a table below to describe them.
|
Example5 == 10 would be false
------------------------------------------------------------------ 5 + 10 = 15 ------------------------------------------------------------------ 15 - 5 = 10 ------------------------------------------------------------------ 3 * 5 = 15 ------------------------------------------------------------------ 12/4 = 3 ------------------------------------------------------------------ 15 ++ increments code by one ------------------------------------------------------------------ 15 -- decrements code by one ------------------------------------------------------------------ 15 != 5 or 20 <> 30 because neither one is equal ------------------------------------------------------------------ (15 == 15 && 15 - 5 = 10) is true ------------------------------------------------------------------ (10 == 10 || 5 == 5) is true ------------------------------------------------------------------ !(10 == 5) is true because 10 doesn't equal 5 ------------------------------------------------------------------ 10 > 5 is true ------------------------------------------------------------------ 8 < 10 is true but 10 < 5 is not true ------------------------------------------------------------------ 10 >= 5 is true but 5 >= 10 is not true ------------------------------------------------------------------ 8 <= 10 is true ------------------------------------------------------------------ |
An example way to use all these operators is with two variables were you want to know say if one is equal to another and display a custom message if there true and a login page if there not. A rudimentary code that probably won't work but will show you what i mean would be:
<?php
$Name1 = "this is name one" ;
$Name2 = "this is the other name" ;
Name1 == Name 2;
print "Your are visitor one";
Name != Name2;
print "you are not visitor one";
?>
<?php
$Name1 = "this is name one" ;
$Name2 = "this is the other name" ;
Name1 == Name 2;
print "Your are visitor one";
Name != Name2;
print "you are not visitor one";
?>