Escolar Documentos
Profissional Documentos
Cultura Documentos
(Hypertext Preprocessor)
Overview of PHP
PHP files can contain text, HTML tags and scripts and file extension
of ".php" or ".phtml
PHP Syntax
PHP code is executed on the server, and the plain HTML result is
sent to the browser.
Syntax: It is starts with <?php and ends with ?>. A PHP scripting block can be
placed anywhere in the document.
<?php
?>
Comments in
<html>
<body>
PHP
<?php
//This is a comment
Examples:
define(YELLOW, #FFFF00);
define(PI, 3.14);
define(NL, <br>\n);
Data types
Variables
$var_name
= value;
All variables
in PHP start
with a $ sign symbol.
<?php
$text=Welcome";
String variable:
echo $text;
?>
Operators
Arithmetic Operators
Assignment Operators
Comparison Operators
==,
!=,
<>,
>,
<,
>=,
<=
/ (Division),
% (Modulus ),
Conditional Statements
if Statement
if (condition)
if...else Statement
code to be executed if condition is true;
else
code
to be
executed
if condition
false;
execute
some
code
if a condition
is trueisand
another code if the condition is false
if (condition)
code to be executed if condition is true;
elseif (condition)
code to be executed if condition is true;
else
code to be executed if condition is false;
if...elseif....else Statement
Switch Statement
Loops
while Loop
do
{
code to be executed;
}
execute
the block
while (condition);
do...while Statement
always
of code once, it will then check the
condition, and repeat the loop while the condition is true.
Loops (cont)
for Loop
The for loop is used when you know in advance how many times
for (init;
condition;
increment)
the
script
should
run.
{
code to be executed;
}
foreach Loop
Form
<?php
$employee_name=$_POST["employee"];
print $employee_name;
?>
result.php
$_GET Function
http://www.xyz.com/form.php?name=Denny&age=20
$_POST Function
Thank You