Php Lesson 1 :- Basic Php Operations
(383 reads)
Using Basic PHP Syntax
A Php file contains Php Scripting as well as HTML Tags.
Here is a PHP script which sends the text "Hello World" to the browser:
<html>
<body><?php echo "Hello World"; ?></body>
</html>
The PHP scripting block always starts with <?php and ends with ?>. A
PHP scripting block can be placed anywhere in the document.
Each code line in PHP must end with a semicolon. The semicolon is a separator
and is used to distinguish one set of instructions from another.
There are two basic statements to output text with PHP: echo and print. In
the example above we have used the echo statement to output the text "Hello
World".
Using Variables in PHP
When using Php all variables in PHP start with a $ sign symbol. Some Php variables
may contain strings, numbers, or arrays.
Below, the PHP script assigns the string "Hello World" to a variable
called $txt:
<html>
<body><?php
$txt="Hello World";
echo $txt;
?></body>
</html>
In Php to concatenate two or more variables together, use the dot (.) operator:
<html>
<body><?php
$txt1="Hello World";
$txt2="1234";
echo $txt1 . " " . $txt2 ;
?></body>
</html>
The output of the script above will be: "Hello World 1234".
Using comments in PHP
When using PHP, we use // to make a single-line comment or /* and */ to make
a large comment block.
<html>
<body><?php//This is a comment/*
This is
a comment
block
*/?></body>
</html>
Using PHP Operators
Here is a list of PHP operators.
Php Arithmetic Operators
| Operator |
Description |
| + |
Addition |
| - |
Subtraction |
| * |
Multiplication |
| / |
Division |
| % |
Modulus (division remainder) |
| ++ |
Increment |
| -- |
Decrement |
Php Assignment Operators
| Operator |
Example |
| = |
x=y |
| += |
x+=y |
| -= |
x-=y |
| *= |
x*=y |
| /= |
x/=y |
| %= |
x%=y |
Php Comparison Operators
| Operator |
Description |
| == |
is equal to |
| != |
is not equal |
| > |
is greater than |
| < |
is less than |
| >= |
is greater than or equal to |
| <= |
is less than or equal to |
Php Logical Operators
| Operator |
Description |
| && |
and |
| || |
or |
| ! |
not |
|