php1
php1
-PHP instructions could coexist with the HTML tags in the same file. So those instructions have to be
delimited by the start and end PHP tags:
-A line which starts with // or # is considered as a comment, same is the sentence written between /*
and */
2. PHP variables
Each variable must start with the $ followed by letters and could contain numbers or the underscore _.
Examples :
3. Constants
Example :
define (“Pi”,3.14);
4. special characters
\n or \r new line
\t tabulation
\\ back slash
\$ the $ character
5. Operators
Assignments: =, += ,-=,*=,/=,++, --
mathematic: + - / * %
comparison: == != < > <= >=
logic: && or AND ,|| or OR , XOR , !
concatenation: .
6. Functions
- function definition
function my_function_name(type1 parameter1,type2 parameter2, type3 parameter3){
//instructions
}
- function call
my_function( value1, value2, value3);
if the function is written in a separated PHP file, we have to call it first.
Example :
Let a function factorial defined in a file called “ functions.php”. Then to call it, we have to write the
following code:
<?php
include('functions.php');
echo 'the factorial of 7 is '.factorial(7);
?>
When a function returns a value, we can save it in a variable like this
definition
int sum (int $a, int $b)
{ return $a+$b; }
call
$s=sum(198,3);
7. echo function
- echo $var;
echo „<b>course</b>‟ ;
or do the inverse